FtpDriverInterface
The low-level transport contract behind the {@see FtpClient}.
Every interaction with the underlying protocol funnels through this interface, which serves two purposes:
- Testability — the whole client logic (connection lifecycle, transfers, listing, retries) is exercised against an in-memory fake, so no live server is required to reach full coverage.
- Extensibility — the production NativeFtpDriver wraps
ext-ftp; an SFTP driver could implement the same contract later without touching the client.
A driver is stateful: it owns the underlying session/handle once connect() succeeds, and exposes the remaining operations against that session.
Tags
Table of Contents
Methods
- append() : bool
- Appends the contents of a local file to a remote file.
- changeDirectory() : bool
- Changes the current working directory.
- changeToParentDirectory() : bool
- Moves up to the parent directory.
- chmod() : bool
- Changes the permissions of a remote file.
- connect() : bool
- Opens the control connection to the server.
- currentDirectory() : string|false
- Returns the current working directory.
- delete() : bool
- Deletes a remote file.
- disconnect() : bool
- Closes the connection and releases the underlying handle.
- get() : bool
- Downloads a remote file to the local filesystem.
- isConnected() : bool
- Indicates whether a connection is currently open.
- lastModified() : int
- Returns the last-modified time of a remote file, as a Unix timestamp.
- listNames() : array<int, string>|false
- Returns the list of names in a directory.
- login() : bool
- Authenticates against the currently open connection.
- makeDirectory() : bool
- Creates a remote directory.
- mlsd() : array<int, array<string, mixed>>|false
- Returns the structured (MLSD) directory listing when the server supports it.
- put() : bool
- Uploads a local file to the server.
- rawList() : array<int, string>|false
- Returns the raw directory listing, one server line per entry.
- removeDirectory() : bool
- Removes a remote directory.
- rename() : bool
- Renames or moves a remote file or directory.
- setOption() : bool
- Sets a runtime option on the connection.
- setPassive() : bool
- Toggles passive transfer mode.
- size() : int
- Returns the size of a remote file, in bytes.
Methods
append()
Appends the contents of a local file to a remote file.
public
append(string $remoteFile, string $localFile, int $mode) : bool
Parameters
- $remoteFile : string
-
The destination path on the server.
- $localFile : string
-
The source path on the local filesystem.
- $mode : int
-
The transfer mode (
FTP_ASCIIorFTP_BINARY).
Return values
bool —True on success, false on failure.
changeDirectory()
Changes the current working directory.
public
changeDirectory(string $directory) : bool
Parameters
- $directory : string
-
The target directory.
Return values
bool —True on success, false on failure.
changeToParentDirectory()
Moves up to the parent directory.
public
changeToParentDirectory() : bool
Return values
bool —True on success, false on failure.
chmod()
Changes the permissions of a remote file.
public
chmod(int $mode, string $remoteFile) : bool
Parameters
- $mode : int
-
The new permissions, as an octal value.
- $remoteFile : string
-
The remote path.
Return values
bool —True on success, false on failure.
connect()
Opens the control connection to the server.
public
connect(string $host, int $port, int $timeout, bool $secure) : bool
Parameters
- $host : string
-
The remote host name or IP address.
- $port : int
-
The remote control-channel port.
- $timeout : int
-
The connection timeout, in seconds.
- $secure : bool
-
Whether to open a TLS-secured (FTPS) connection.
Return values
bool —True on success, false on failure.
currentDirectory()
Returns the current working directory.
public
currentDirectory() : string|false
Return values
string|false —The directory path, or false on failure.
delete()
Deletes a remote file.
public
delete(string $remoteFile) : bool
Parameters
- $remoteFile : string
-
The path of the file to delete.
Return values
bool —True on success, false on failure.
disconnect()
Closes the connection and releases the underlying handle.
public
disconnect() : bool
Return values
bool —True on success, false on failure.
get()
Downloads a remote file to the local filesystem.
public
get(string $localFile, string $remoteFile, int $mode) : bool
Parameters
- $localFile : string
-
The destination path on the local filesystem.
- $remoteFile : string
-
The source path on the server.
- $mode : int
-
The transfer mode (
FTP_ASCIIorFTP_BINARY).
Return values
bool —True on success, false on failure.
isConnected()
Indicates whether a connection is currently open.
public
isConnected() : bool
Return values
bool —True when a session is established.
lastModified()
Returns the last-modified time of a remote file, as a Unix timestamp.
public
lastModified(string $remoteFile) : int
Parameters
- $remoteFile : string
-
The remote path.
Return values
int —The Unix timestamp, or -1 when it cannot be determined.
listNames()
Returns the list of names in a directory.
public
listNames(string $directory) : array<int, string>|false
Parameters
- $directory : string
-
The directory to list.
Return values
array<int, string>|false —The names, or false on failure.
login()
Authenticates against the currently open connection.
public
login(string $username, string $password) : bool
Parameters
- $username : string
-
The login user name.
- $password : string
-
The login password.
Return values
bool —True on success, false when the server rejects the credentials.
makeDirectory()
Creates a remote directory.
public
makeDirectory(string $directory) : bool
Parameters
- $directory : string
-
The directory to create.
Return values
bool —True on success, false on failure.
mlsd()
Returns the structured (MLSD) directory listing when the server supports it.
public
mlsd(string $directory) : array<int, array<string, mixed>>|false
Parameters
- $directory : string
-
The directory to list.
Return values
array<int, array<string, mixed>>|false —The entries, or false when unsupported/failed.
put()
Uploads a local file to the server.
public
put(string $remoteFile, string $localFile, int $mode) : bool
Parameters
- $remoteFile : string
-
The destination path on the server.
- $localFile : string
-
The source path on the local filesystem.
- $mode : int
-
The transfer mode (
FTP_ASCIIorFTP_BINARY).
Return values
bool —True on success, false on failure.
rawList()
Returns the raw directory listing, one server line per entry.
public
rawList(string $directory, bool $recursive) : array<int, string>|false
Parameters
- $directory : string
-
The directory to list.
- $recursive : bool
-
Whether to recurse into sub-directories.
Return values
array<int, string>|false —The raw lines, or false on failure.
removeDirectory()
Removes a remote directory.
public
removeDirectory(string $directory) : bool
Parameters
- $directory : string
-
The directory to remove.
Return values
bool —True on success, false on failure.
rename()
Renames or moves a remote file or directory.
public
rename(string $from, string $to) : bool
Parameters
- $from : string
-
The current path.
- $to : string
-
The new path.
Return values
bool —True on success, false on failure.
setOption()
Sets a runtime option on the connection.
public
setOption(int $option, int|bool $value) : bool
Parameters
- $option : int
-
One of the FtpConnectionOption constants.
- $value : int|bool
-
The value to assign.
Return values
bool —True on success, false on failure.
setPassive()
Toggles passive transfer mode.
public
setPassive(bool $passive) : bool
Parameters
- $passive : bool
-
Whether passive mode should be enabled.
Return values
bool —True on success, false on failure.
size()
Returns the size of a remote file, in bytes.
public
size(string $remoteFile) : int
Parameters
- $remoteFile : string
-
The remote path.
Return values
int —The size in bytes, or -1 when it cannot be determined.