You are here

public function FTPExtension::chmodJailed in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/FileTransfer/FTPExtension.php \Drupal\Core\FileTransfer\FTPExtension::chmodJailed()

Changes the permissions of the file / directory specified in $path.

Parameters

string $path: Path to change permissions of.

int $mode: The new file permission mode to be passed to chmod().

bool $recursive: Pass TRUE to recursively chmod the entire directory specified in $path.

Overrides ChmodInterface::chmodJailed

See also

http://php.net/chmod

File

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

Class

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

Namespace

Drupal\Core\FileTransfer

Code

public function chmodJailed($path, $mode, $recursive) {
  if (!ftp_chmod($this->connection, $mode, $path)) {
    throw new FileTransferException("Unable to set permissions on %file", 0, [
      '%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);
    }
  }
}