You are here

class FileTransferFTPExtension in Drupal 7

Hierarchy

Expanded class hierarchy of FileTransferFTPExtension

1 string reference to 'FileTransferFTPExtension'
FileTransferFTP::factory in includes/filetransfer/ftp.inc
Return an object which can implement the FTP protocol.

File

includes/filetransfer/ftp.inc, line 51

View source
class FileTransferFTPExtension extends FileTransferFTP implements FileTransferChmodInterface {
  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");
    }
  }
  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,
      ));
    }
  }
  protected function createDirectoryJailed($directory) {
    if (!ftp_mkdir($this->connection, $directory)) {
      throw new FileTransferException("Cannot create directory @directory", NULL, array(
        "@directory" => $directory,
      ));
    }
  }
  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,
      ));
    }
  }
  protected function removeFileJailed($destination) {
    if (!ftp_delete($this->connection, $destination)) {
      throw new FileTransferException("Unable to remove to file @file", NULL, array(
        '@file' => $destination,
      ));
    }
  }
  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;
  }
  public function isFile($path) {
    return ftp_size($this->connection, $path) != -1;
  }
  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);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileTransfer::$hostname protected property
FileTransfer::$password protected property 1
FileTransfer::$port protected property 1
FileTransfer::$username protected property 1
FileTransfer::checkPath final protected function Checks that the path is inside the jail and throws an exception if not.
FileTransfer::chmod final public function
FileTransfer::copyDirectory final public function Copies a directory.
FileTransfer::copyDirectoryJailed protected function Copies a directory. 1
FileTransfer::copyFile final public function Copies a file.
FileTransfer::createDirectory final public function Creates a directory.
FileTransfer::findChroot function Return the chroot property for this connection.
FileTransfer::fixRemotePath final protected function Returns a modified path suitable for passing to the server. If a path is a windows path, makes it POSIX compliant by removing the drive letter. If $this->chroot has a value, it is stripped from the path to allow for chroot'd filetransfer systems.
FileTransfer::removeDirectory final public function Removes a directory.
FileTransfer::removeFile final public function Removes a file.
FileTransfer::sanitizePath function Changes backslashes to slashes, also removes a trailing slash.
FileTransfer::setChroot function Sets the chroot and changes the jail to match the correct path scheme
FileTransfer::__get function Implementation of the magic __get() method.
FileTransferFTP::factory static function Return an object which can implement the FTP protocol. Overrides FileTransfer::factory
FileTransferFTP::getSettingsForm public function Returns the form to configure the FileTransfer class for FTP. Overrides FileTransfer::getSettingsForm
FileTransferFTP::__construct public function The constructor for the UpdateConnection class. This method is also called from the classes that extend this class and override this method. Overrides FileTransfer::__construct
FileTransferFTPExtension::chmodJailed function Changes the permissions of the file / directory specified in $path Overrides FileTransferChmodInterface::chmodJailed
FileTransferFTPExtension::connect public function Connect to the server. Overrides FileTransfer::connect
FileTransferFTPExtension::copyFileJailed protected function Copies a file. Overrides FileTransfer::copyFileJailed
FileTransferFTPExtension::createDirectoryJailed protected function Creates a directory. Overrides FileTransfer::createDirectoryJailed
FileTransferFTPExtension::isDirectory public function Checks if a particular path is a directory Overrides FileTransfer::isDirectory
FileTransferFTPExtension::isFile public function Checks if a particular path is a file (not a directory). Overrides FileTransfer::isFile
FileTransferFTPExtension::removeDirectoryJailed protected function Removes a directory. Overrides FileTransfer::removeDirectoryJailed
FileTransferFTPExtension::removeFileJailed protected function Removes a file. Overrides FileTransfer::removeFileJailed