NativeFtpDriver implements FtpDriverInterface
The production {@see FtpDriverInterface} implementation, backed by `ext-ftp`.
Each method is a thin pass-through to the matching ftp_* function: the driver
holds the Connection handle and carries no business logic. Because these
calls cannot run without a live server, the class is excluded from coverage —
the client logic that drives it is fully tested against an in-memory fake. An
optional integration suite can exercise this driver against a real server.
Tags
Table of Contents
Interfaces
- FtpDriverInterface
- The low-level transport contract behind the {@see FtpClient}.
Properties
- $connection : Connection|null
- The underlying ext-ftp connection handle, or null when disconnected.
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.
Properties
$connection
The underlying ext-ftp connection handle, or null when disconnected.
private
Connection|null
$connection
= null
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).
Tags
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.
Tags
Return values
bool —True on success, false on failure.
changeToParentDirectory()
Moves up to the parent directory.
public
changeToParentDirectory() : bool
Tags
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.
Tags
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.
Tags
Return values
bool —True on success, false on failure.
currentDirectory()
Returns the current working directory.
public
currentDirectory() : string|false
Tags
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.
Tags
Return values
bool —True on success, false on failure.
disconnect()
Closes the connection and releases the underlying handle.
public
disconnect() : bool
Tags
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).
Tags
Return values
bool —True on success, false on failure.
isConnected()
Indicates whether a connection is currently open.
public
isConnected() : bool
Tags
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.
Tags
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.
Tags
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.
Tags
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.
Tags
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.
Tags
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).
Tags
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.
Tags
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.
Tags
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.
Tags
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.
Tags
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.
Tags
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.
Tags
Return values
int —The size in bytes, or -1 when it cannot be determined.