class Local extends FileTransfer implements ChmodInterface (View source)

Defines the local connection class for copying files as the httpd user.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected string $username

The username for this file transfer.

from  FileTransfer
protected string $password

The password for this file transfer.

from  FileTransfer
protected string $hostname

The hostname for this file transfer.

from  FileTransfer
protected int $port

The port for this file transfer.

from  FileTransfer
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected FileSystemInterface $fileSystem

The file system service.

Methods

__construct($jail, FileSystemInterface $file_system)

Constructs a Drupal\Core\FileTransfer\FileTransfer object.

static object
factory(string $jail, array $settings)

Defines a factory method for this class.

string|bool
__get(string $name)

Implements the magic __get() method.

connect()

Connects to the server.

copyDirectory(string $source, string $destination)

Copies a directory.

chmod(string $path, int $mode, bool $recursive = FALSE)

Changes the permissions of the specified $path (file or directory).

createDirectory(string $directory)

Creates a directory.

removeDirectory(string $directory)

Removes a directory.

copyFile(string $source, string $destination)

Copies a file.

removeFile(string $destination)

Removes a file.

checkPath(string $path)

Checks that the path is inside the jail and throws an exception if not.

string
fixRemotePath(string $path, bool $strip_chroot = TRUE)

Returns a modified path suitable for passing to the server.

string
sanitizePath(string $path)

Changes backslashes to slashes, also removes a trailing slash.

copyDirectoryJailed(string $source, string $destination)

Copies a directory.

createDirectoryJailed(string $directory)

Creates a directory.

removeDirectoryJailed(string $directory)

Removes a directory.

copyFileJailed(string $source, string $destination)

Copies a file.

removeFileJailed($file)

Removes a file.

bool
isDirectory(string $path)

Checks if a particular path is a directory.

bool
isFile(string $path)

Checks if a particular path is a file (not a directory).

string|bool
findChroot()

Returns the chroot property for this connection.

setChroot()

Sets the chroot and changes the jail to match the correct path scheme.

array
getSettingsForm()

Returns a form to collect connection settings credentials.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

chmodJailed(string $path, int $mode, bool $recursive)

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

Details

__construct($jail, FileSystemInterface $file_system)

Constructs a Drupal\Core\FileTransfer\FileTransfer object.

Parameters

$jail

The full path where all file operations performed by this object will be restricted to. This prevents the FileTransfer classes from being able to touch other parts of the filesystem.

FileSystemInterface $file_system

static object factory(string $jail, array $settings)

Defines a factory method for this class.

Classes that extend this class must override the factory() static method. They should return a new instance of the appropriate FileTransfer subclass.

Parameters

string $jail

The full path where all file operations performed by this object will be restricted to. This prevents the FileTransfer classes from being able to touch other parts of the filesystem.

array $settings

An array of connection settings for the FileTransfer subclass. If the getSettingsForm() method uses any nested settings, the same structure will be assumed here.

Return Value

object

New instance of the appropriate FileTransfer subclass.

Exceptions

FileTransferException

string|bool __get(string $name)

Implements the magic __get() method.

If the connection isn't set to anything, this will call the connect() method and return the result; afterwards, the connection will be returned directly without using this method.

Parameters

string $name

The name of the variable to return.

Return Value

string|bool

The variable specified in $name.

connect()

Connects to the server.

final copyDirectory(string $source, string $destination)

Copies a directory.

Parameters

string $source

The source path.

string $destination

The destination path.

final chmod(string $path, int $mode, bool $recursive = FALSE)

Changes the permissions of the specified $path (file or directory).

Parameters

string $path

The file / directory to change the 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.

Exceptions

FileTransferException

See also

http://php.net/chmod

final createDirectory(string $directory)

Creates a directory.

Parameters

string $directory

The directory to be created.

final removeDirectory(string $directory)

Removes a directory.

Parameters

string $directory

The directory to be removed.

final copyFile(string $source, string $destination)

Copies a file.

Parameters

string $source

The source file.

string $destination

The destination file.

final removeFile(string $destination)

Removes a file.

Parameters

string $destination

The destination file to be removed.

final protected checkPath(string $path)

Checks that the path is inside the jail and throws an exception if not.

Parameters

string $path

A path to check against the jail.

Exceptions

FileTransferException

final protected string fixRemotePath(string $path, bool $strip_chroot = TRUE)

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 and $strip_chroot is TRUE, it is stripped from the path to allow for chroot'd filetransfer systems.

Parameters

string $path

The path to modify.

bool $strip_chroot

Whether to remove the path in $this->chroot.

Return Value

string

The modified path.

string sanitizePath(string $path)

Changes backslashes to slashes, also removes a trailing slash.

Parameters

string $path

The path to modify.

Return Value

string

The modified path.

protected copyDirectoryJailed(string $source, string $destination)

Copies a directory.

We need a separate method to make sure the $destination is in the jail.

Parameters

string $source

The source path.

string $destination

The destination path.

protected createDirectoryJailed(string $directory)

Creates a directory.

Parameters

string $directory

The directory to be created.

protected removeDirectoryJailed(string $directory)

Removes a directory.

Parameters

string $directory

The directory to be removed.

protected copyFileJailed(string $source, string $destination)

Copies a file.

Parameters

string $source

The source file.

string $destination

The destination file.

protected removeFileJailed($file)

Removes a file.

Parameters

$file

bool isDirectory(string $path)

Checks if a particular path is a directory.

Parameters

string $path

The path to check

Return Value

bool

TRUE if the specified path is a directory, FALSE otherwise.

bool isFile(string $path)

Checks if a particular path is a file (not a directory).

Parameters

string $path

The path to check.

Return Value

bool

TRUE if the specified path is a file, FALSE otherwise.

string|bool findChroot()

Returns the chroot property for this connection.

It does this by moving up the tree until it finds itself

Return Value

string|bool

If successful, the chroot path for this connection, otherwise FALSE.

setChroot()

Sets the chroot and changes the jail to match the correct path scheme.

array getSettingsForm()

Returns a form to collect connection settings credentials.

Implementing classes can either extend this form with fields collecting the specific information they need, or override it entirely.

Return Value

array

An array that contains a Form API definition.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

chmodJailed(string $path, int $mode, bool $recursive)

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.