The FTP functions in PHP provide client access to file servers via the File Transfer Protocol (FTP).
These functions allow you to open, log in to, and close connections, as well as upload, download, rename, delete, and retrieve information about files from FTP servers. Note that not all FTP functions may work with every server or produce the same results.
Available since PHP 3, if you only need to read from or write to a file on an FTP server, consider using the ftp://
wrapper with the Filesystem functions for a simpler and more intuitive interface.
To use these functions, PHP must be compiled with the --enable-ftp
option.
The Windows version of PHP includes built-in support for this extension.
Function |
Description |
ftp_alloc() |
Reserves space for a file to be uploaded to the FTP server. |
ftp_cdup() |
Navigates to the parent directory on the FTP server. |
ftp_chdir() |
Changes the current directory on the FTP server. |
ftp_chmod() |
Sets file permissions on the FTP server. |
ftp_close() |
Terminates an FTP connection. |
ftp_connect() |
Establishes an FTP connection. |
ftp_delete() |
Removes a file from the FTP server. |
ftp_exec() |
Executes a command on the FTP server. |
ftp_fget() |
Downloads a file from the FTP server and writes it to an open local file. |
ftp_fput() |
Uploads data from an open file and saves it to a file on the FTP server. |
ftp_get() |
Retrieves a file from the FTP server. |
ftp_get_option() |
Returns the runtime settings of the FTP connection. |
ftp_login() |
Authenticates to the FTP connection. |
ftp_mdtm() |
Retrieves the last modified time of a specified file. |
ftp_mkdir() |
Creates a new directory on the FTP server. |
ftp_mlsd() |
Retrieves the list of files in the specified directory. |
ftp_nb_continue() |
Continues retrieving or sending a file in a non-blocking manner. |
ftp_nb_fget() |
Downloads a file from the FTP server and saves it to an open file in a non-blocking manner. |
ftp_nb_fput() |
Uploads data from an open file to a file on the FTP server in a non-blocking manner. |
ftp_nb_get() |
Downloads a file from the FTP server in a non-blocking manner. |
ftp_nb_put() |
Uploads a file to the FTP server without blocking other operations. |
ftp_nlist() |
Provides a list of files in the specified directory on the FTP server. |
ftp_pasv() |
Enables or disables passive mode. |
ftp_put() |
Transfers a file to the FTP server. |
ftp_pwd() |
Returns the name of the current directory. |
ftp_quit() |
Alternative name for |
ftp_raw() |
Issues a raw command to the FTP server. |
ftp_rawlist() |
Returns a list of files along with their information from a specified directory. |
ftp_rename() |
Renames a file or directory on the FTP server. |
ftp_rmdir() |
Removes an empty directory from the FTP server. |
ftp_set_option() |
Configures runtime options for the FTP connection. |
ftp_site() |
Issues an FTP SITE command to the FTP server. |
ftp_size() |
Retrieves the size of the specified file. |
ftp_ssl_connect() |
Establishes a secure SSL-FTP connection. |
ftp_systype() |
Retrieves the system type identifier of the FTP server. |
Constant |
Type |
Description |
FTP_ASCII |
Integer |
|
FTP_AUTOSEEK |
Integer |
|
FTP_AUTORESUME |
Integer |
|
FTP_BINARY |
Integer |
|
FTP_FAILED |
Integer |
The asynchronous transfer has failed. |
FTP_FINISHED |
Integer |
The asynchronous transfer is complete. |
FTP_IMAGE |
Integer |
Alternative name for |
FTP_MOREDATA |
Integer |
The asynchronous transfer is underway. |
FTP_TEXT |
Integer |
Alias of FTP_ASCII |
FTP_TIMEOUT_SEC |
Integer |
The timeout set for network operations. |
FTP_USEPASVADDRESS |
Boolean |
|