PHP FTP
Functions
PHP FTP Introduction
FTP functions provide client access to file servers via the File Transfer Protocol (FTP).
FTP functions are used to open, log in, and close connections, as well as to upload, download, rename, delete, and retrieve file information from the server. Not all FTP functions work on every server or return the same results. FTP functions have been available since PHP 3.
These functions are used for detailed access to FTP servers. If you only need to read from or write to an FTP server, it is recommended to use the ftp://
wrapper in the Filesystem functions.
Installation
The Windows version of PHP has built-in support for the FTP extension. No additional libraries need to be loaded to use the FTP functions.
However, if you are running the Linux version of PHP, please include the --enable-ftp
option (for PHP 4 or later) or --with-ftp
option (for PHP 3) when compiling PHP.
PHP FTP Functions
PHP: Indicates the earliest PHP version that supports the function.
Function | Description | PHP |
---|---|---|
ftp_alloc() | Allocates space for a file to be uploaded to the FTP server. | 5 |
ftp_cdup() | Changes the current directory to the parent directory on the FTP server. | 3 |
ftp_chdir() | Changes the current directory on the FTP server. | 3 |
ftp_chmod() | Sets permissions on a file via FTP. | 5 |
ftp_close() | Closes an FTP connection. | 4 |
ftp_connect() | Opens an FTP connection. | 3 |
ftp_delete() | Deletes a file on the FTP server. | 3 |
ftp_exec() | Executes a program/command on the FTP server. | 4 |
ftp_fget() | Downloads a file from the FTP server and saves it to a local open file. | 3 |
ftp_fput() | Uploads an open file and saves it as a file on the FTP server. | 3 |
ftp_get_option() | Returns various runtime options of the FTP connection. | 4 |
ftp_get() | Downloads a file from the FTP server. | 3 |
ftp_login() | Logs in to the FTP server. | 3 |
ftp_mdtm() | Returns the last modification time of the specified file. | 3 |
ftp_mkdir() | Creates a new directory on the FTP server. | 3 |
ftp_nb_continue() | Continues retrieving/sending a file (non-blocking). | 4 |
ftp_nb_fget() | Downloads a file from the FTP server and saves it to a local open file (non-blocking). | 4 |
ftp_nb_fput() | Uploads an open file and saves it as a file on the FTP server (non-blocking). | 4 |
ftp_nb_get() | Downloads a file from the FTP server (non-blocking). | 4 |
ftp_nb_put() | Uploads a file to the FTP server (non-blocking). | 4 |
ftp_nlist() | Returns a list of files in the specified directory on the FTP server. | 3 |
ftp_pasv() | Turns passive mode on or off. | 3 |
ftp_put() | Uploads a file to the FTP server. | 3 |
ftp_pwd() | Returns the current directory name. | 3 |
ftp_quit() | Alias of ftp_close(). | 3 |
ftp_raw() | Sends a raw command to the FTP server. | 5 |
ftp_rawlist() | Returns a detailed list of files in the specified directory. | 3 |
ftp_rename() | Renames a file or directory on the FTP server. | 3 |
ftp_rmdir() | Deletes a directory on the FTP server. | 3 |
ftp_set_option() | Sets various runtime options for the FTP connection. | 4 |
ftp_site() | Sends a SITE command to the server. | 3 |
ftp_size() | Returns the size of the specified file. | 3 |
ftp_ssl_connect() | Opens a secure SSL-FTP connection. | 4 |
ftp_systype() | Returns the system type identifier of the FTP server. | 3 |
PHP FTP Constants
PHP: Indicates the earliest PHP version that supports the constant.
Constant | Description | PHP |
---|---|---|
FTP_ASCII | 3 | |
FTP_TEXT | 3 | |
FTP_BINARY | 3 | |
FTP_IMAGE | 3 | |
FTP_TIMEOUT_SEC | 3 | |
FTP_AUTOSEEK | 4 | |
FTP_AUTORESUME | Automatically determines resume and start positions for GET and PUT requests | 4 |
FTP_FAILED | Asynchronous transfer failed | 4 |
FTP_FINISHED | Asynchronous transfer successful | 4 |
FTP_MOREDATA | Asynchronous transfer is active | 4 |