PHP Function Reference

PHP - FTP



The functions in this extension implement client access to files servers through the File Transfer Protocol (FTP). The FTP functions are used to open, login and close connections, as well as upload, download, rename, delete, and get information on files from file servers. Not all of the FTP functions will work with every server or return the same results.

If you only wish to read from or write to a file on an FTP server, consider using the ftp:// wrapper with the Filesystem functions which provide a simpler and more intuitive interface.

Installation

In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP.

The Windows version of PHP has built-in support for this extension.

PHP FTP Functions

FunctionsDescription
ftp_chmod() Set permissions on a file via FTP.
ftp_chdir() Changes the current directory on a FTP server.
ftp_close() Closes an FTP connection.
ftp_connect() Opens an FTP connection.
ftp_delete() Deletes a file on the FTP server.
ftp_fget() Downloads a file from the FTP server and saves to an open file.
ftp_fput() Uploads from an open file to the FTP server.
ftp_get() Downloads a file from the FTP server.
ftp_get_option() Retrieves various runtime behaviors of the specified FTP connection.
ftp_login() Logs in to an FTP connection.
ftp_mkdir() Creates a directory on the FTP server.
ftp_nb_continue() Continues retrieving/sending a file (non-blocking).
ftp_nb_fget() Downloads a file from the FTP server and writes it to an open file (non-blocking).
ftp_nb_fput() Uploads a file from an open file to the FTP server (non-blocking).
ftp_nb_get() Downloads a file from the FTP server and writes it to a local file (non-blocking).
ftp_nb_put() Uploads a file on the FTP server (non-blocking).
ftp_pasv() Turns passive mode on or off.
ftp_put() Uploads a file to the FTP server.
ftp_pwd() Returns the current directory name.
ftp_rename() Renames a file or a directory on the FTP server.
ftp_rmdir() Removes a directory on the FTP server.
ftp_size() Returns the size of the given file.
ftp_quit() Closes an FTP connection. Alias of ftp_close() function.
ftp_set_option() Sets runtime options of the specified FTP connection.
ftp_ssl_connect() Opens a Secure SSL-FTP connection FTP connection.
ftp_systype() Returns the system type identifier of the remote FTP server.

PHP FTP Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

ConstantsTypeDescription
FTP_ASCIIInteger
FTP_AUTOSEEKIntegerSee ftp_set_option() for information.
FTP_AUTORESUMEIntegerAutomatically determine resume position and start position for GET and PUT requests (only works if FTP_AUTOSEEK is enabled)
FTP_FAILEDIntegerAsynchronous transfer has failed
FTP_FINISHEDIntegerAsynchronous transfer has finished
FTP_MOREDATAIntegerAsynchronous transfer is still active
FTP_TEXTIntegerAlias of FTP_ASCII.
FTP_BINARYInteger
FTP_IMAGEIntegerAlias of FTP_BINARY.
FTP_TIMEOUT_SECIntegerSee ftp_set_option() for information.
FTP_USEPASVADDRESSBooleanSee ftp_set_option() for information.

5