Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 68 |
FTPExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
702 | |
0.00% |
0 / 68 |
connect | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 8 |
|||
copyFileJailed | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
createDirectoryJailed | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
removeDirectoryJailed | |
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 25 |
|||
removeFileJailed | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
isDirectory | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
|||
isFile | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
chmodJailed | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 13 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\FileTransfer\FTPExtension. | |
*/ | |
namespace Drupal\Core\FileTransfer; | |
/** | |
* Defines a file transfer class using the PHP FTP extension. | |
*/ | |
class FTPExtension extends FTP implements ChmodInterface { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function connect() { | |
$this->connection = ftp_connect($this->hostname, $this->port); | |
if (!$this->connection) { | |
throw new FileTransferException("Cannot connect to FTP Server, check settings"); | |
} | |
if (!ftp_login($this->connection, $this->username, $this->password)) { | |
throw new FileTransferException("Cannot log in to FTP server. Check username and password"); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function copyFileJailed($source, $destination) { | |
if (!@ftp_put($this->connection, $destination, $source, FTP_BINARY)) { | |
throw new FileTransferException("Cannot move @source to @destination", NULL, array("@source" => $source, "@destination" => $destination)); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function createDirectoryJailed($directory) { | |
if (!ftp_mkdir($this->connection, $directory)) { | |
throw new FileTransferException("Cannot create directory @directory", NULL, array("@directory" => $directory)); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function removeDirectoryJailed($directory) { | |
$pwd = ftp_pwd($this->connection); | |
if (!ftp_chdir($this->connection, $directory)) { | |
throw new FileTransferException("Unable to change to directory @directory", NULL, array('@directory' => $directory)); | |
} | |
$list = @ftp_nlist($this->connection, '.'); | |
if (!$list) { | |
$list = array(); | |
} | |
foreach ($list as $item) { | |
if ($item == '.' || $item == '..') { | |
continue; | |
} | |
if (@ftp_chdir($this->connection, $item)) { | |
ftp_cdup($this->connection); | |
$this->removeDirectory(ftp_pwd($this->connection) . '/' . $item); | |
} | |
else { | |
$this->removeFile(ftp_pwd($this->connection) . '/' . $item); | |
} | |
} | |
ftp_chdir($this->connection, $pwd); | |
if (!ftp_rmdir($this->connection, $directory)) { | |
throw new FileTransferException("Unable to remove to directory @directory", NULL, array('@directory' => $directory)); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function removeFileJailed($destination) { | |
if (!ftp_delete($this->connection, $destination)) { | |
throw new FileTransferException("Unable to remove to file @file", NULL, array('@file' => $destination)); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function isDirectory($path) { | |
$result = FALSE; | |
$curr = ftp_pwd($this->connection); | |
if (@ftp_chdir($this->connection, $path)) { | |
$result = TRUE; | |
} | |
ftp_chdir($this->connection, $curr); | |
return $result; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function isFile($path) { | |
return ftp_size($this->connection, $path) != -1; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
function chmodJailed($path, $mode, $recursive) { | |
if (!ftp_chmod($this->connection, $mode, $path)) { | |
throw new FileTransferException("Unable to set permissions on %file", NULL, array('%file' => $path)); | |
} | |
if ($this->isDirectory($path) && $recursive) { | |
$filelist = @ftp_nlist($this->connection, $path); | |
if (!$filelist) { | |
//empty directory - returns false | |
return; | |
} | |
foreach ($filelist as $file) { | |
$this->chmodJailed($file, $mode, $recursive); | |
} | |
} | |
} | |
} |