function FTPExtension::removeDirectoryJailed

Same name in other branches
  1. 9 core/lib/Drupal/Core/FileTransfer/FTPExtension.php \Drupal\Core\FileTransfer\FTPExtension::removeDirectoryJailed()
  2. 8.9.x core/lib/Drupal/Core/FileTransfer/FTPExtension.php \Drupal\Core\FileTransfer\FTPExtension::removeDirectoryJailed()
  3. 11.x core/lib/Drupal/Core/FileTransfer/FTPExtension.php \Drupal\Core\FileTransfer\FTPExtension::removeDirectoryJailed()

Overrides FileTransfer::removeDirectoryJailed

File

core/lib/Drupal/Core/FileTransfer/FTPExtension.php, line 45

Class

FTPExtension
Defines a file transfer class using the PHP FTP extension.

Namespace

Drupal\Core\FileTransfer

Code

protected function removeDirectoryJailed($directory) {
    $pwd = ftp_pwd($this->connection);
    if (!ftp_chdir($this->connection, $directory)) {
        throw new FileTransferException("Unable to change the current directory to @directory", 0, [
            '@directory' => $directory,
        ]);
    }
    $list = @ftp_nlist($this->connection, '.');
    if (!$list) {
        $list = [];
    }
    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 the directory @directory", 0, [
            '@directory' => $directory,
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.