PHP FTP Functions

About This Index
This page is the PHP FTP Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn how an FTP session works, how to upload and download files, and when to use SSL on /php/ftp. Use this page when you need a specific helper such as ftp_connect(), ftp_put(), or ftp_nlist().
Start with ftp_connect(), ftp_login(), and ftp_pasv()—then move on to ftp_put(), ftp_get(), and the directory helpers.
How to Call an FTP Function
FTP helpers are global functions—pass the connection from ftp_connect() first, then the other arguments:
$ftp = ftp_connect('ftp.example.com');
if ($ftp === false || !ftp_login($ftp, $user, $pass)) {
exit('Could not connect or log in');
}
ftp_pasv($ftp, true);
$files = ftp_nlist($ftp, '.');
ftp_put($ftp, 'remote.txt', 'local.txt', FTP_BINARY);
ftp_close($ftp); PHP FTP Functions Table
All function guides in this PHP tutorial series (36 tutorials in 6 categories).
Connect & login
6 functionsOpen a plain or SSL connection, sign in, choose passive mode, and close the session.
| Function | Description | Tutorial |
|---|---|---|
ftp_connect() | Open a plain FTP connection to a server. | Try it |
ftp_ssl_connect() | Open an FTP over TLS (FTPS) connection. | Try it |
ftp_login() | Log in to an FTP connection. | Try it |
ftp_pasv() | Turn passive mode on or off. | Try it |
ftp_close() | Close an FTP connection. | Try it |
ftp_quit() | Alias of ftp_close(); close an FTP connection. | Try it |
Transfer files
6 functionsUpload and download files by path or through an open file handle, and reserve space before an upload.
| Function | Description | Tutorial |
|---|---|---|
ftp_get() | Download a file from the server to a local path. | Try it |
ftp_fget() | Download a file from the server into an open file handle. | Try it |
ftp_put() | Upload a local file to the server. | Try it |
ftp_fput() | Upload from an open file handle to the server. | Try it |
ftp_append() | Append the contents of a local file to a remote file. | Try it |
ftp_alloc() | Allocate space for a file to be uploaded. | Try it |
Non-blocking
5 functionsStart large transfers without waiting for them to finish, then continue them in a loop.
| Function | Description | Tutorial |
|---|---|---|
ftp_nb_get() | Start a non-blocking download to a local path. | Try it |
ftp_nb_fget() | Start a non-blocking download into an open file handle. | Try it |
ftp_nb_put() | Start a non-blocking upload of a local file. | Try it |
ftp_nb_fput() | Start a non-blocking upload from an open file handle. | Try it |
ftp_nb_continue() | Continue a non-blocking transfer. | Try it |
List & inspect
6 functionsList directory contents and read details such as size, modification time, and server system type.
| Function | Description | Tutorial |
|---|---|---|
ftp_nlist() | Return an array of file names in a directory. | Try it |
ftp_rawlist() | Return a detailed listing of a directory as raw lines. | Try it |
ftp_mlsd() | Return a parsed, detailed listing of a directory. | Try it |
ftp_size() | Return the size of a remote file in bytes. | Try it |
ftp_mdtm() | Return the last modified time of a remote file. | Try it |
ftp_systype() | Return the system type identifier of the server. | Try it |
Options & raw
5 functionsTune timeouts and behavior, and send raw or server-specific FTP commands.
| Function | Description | Tutorial |
|---|---|---|
ftp_get_option() | Read a runtime option of the FTP connection. | Try it |
ftp_set_option() | Set a runtime option for the FTP connection. | Try it |
ftp_raw() | Send an arbitrary command to the server. | Try it |
ftp_exec() | Ask the server to execute a program or command. | Try it |
ftp_site() | Send a SITE command to the server. | Try it |
Frequently Asked Questions
Start with ftp_alloc()
Open the first guide—syntax, examples, and FAQs.
15 people found this page helpful
