FileTransfer
abstract class FileTransfer (View source)
Defines the base FileTransfer class.
Classes extending this class perform file operations on directories not writable by the webserver. To achieve this, the class should connect back to the server using some backend (for example FTP or SSH). To keep security, the password should always be asked from the user and never stored. For safety, all methods operate only inside a "jail", by default the Drupal root.
Properties
| protected string | $username | The username for this file transfer. |
|
| protected string | $password | The password for this file transfer. |
|
| protected string | $hostname | The hostname for this file transfer. |
|
| protected int | $port | The port for this file transfer. |
Methods
Constructs a Drupal\Core\FileTransfer\FileTransfer object.
Defines a factory method for this class.
Implements the magic __get() method.
Connects to the server.
Copies a directory.
Changes the permissions of the specified $path (file or directory).
Creates a directory.
Removes a directory.
Copies a file.
Removes a file.
Checks that the path is inside the jail and throws an exception if not.
Returns a modified path suitable for passing to the server.
Changes backslashes to slashes, also removes a trailing slash.
Copies a directory.
Creates a directory.
Removes a directory.
Copies a file.
Removes a file.
Checks if a particular path is a directory.
Checks if a particular path is a file (not a directory).
Returns the chroot property for this connection.
Sets the chroot and changes the jail to match the correct path scheme.
Returns a form to collect connection settings credentials.
Details
__construct($jail)
Constructs a Drupal\Core\FileTransfer\FileTransfer object.
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.
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.
abstract
connect()
Connects to the server.
final
copyDirectory(string $source, string $destination)
Copies a directory.
final
chmod(string $path, int $mode, bool $recursive = FALSE)
Changes the permissions of the specified $path (file or directory).
final
createDirectory(string $directory)
Creates a directory.
final
removeDirectory(string $directory)
Removes a directory.
final
copyFile(string $source, string $destination)
Copies a file.
final
removeFile(string $destination)
Removes a file.
final protected
checkPath(string $path)
Checks that the path is inside the jail and throws an exception if not.
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.
string
sanitizePath(string $path)
Changes backslashes to slashes, also removes a trailing slash.
protected
copyDirectoryJailed(string $source, string $destination)
Copies a directory.
We need a separate method to make sure the $destination is in the jail.
abstract protected
createDirectoryJailed(string $directory)
Creates a directory.
abstract protected
removeDirectoryJailed(string $directory)
Removes a directory.
abstract protected
copyFileJailed(string $source, string $destination)
Copies a file.
abstract protected
removeFileJailed(string $destination)
Removes a file.
abstract bool
isDirectory(string $path)
Checks if a particular path is a directory.
abstract 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.
It does this by moving up the tree until it finds itself
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.