PHP FTP Functions

Beginner
6 min read
Updated: Nov 2026
36 function guides
Function index

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().

Beginner path.

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:

PHP
$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 functions

Open a plain or SSL connection, sign in, choose passive mode, and close the session.

FunctionDescriptionTutorial
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 functions

Upload and download files by path or through an open file handle, and reserve space before an upload.

FunctionDescriptionTutorial
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 functions

Start large transfers without waiting for them to finish, then continue them in a loop.

FunctionDescriptionTutorial
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 functions

List directory contents and read details such as size, modification time, and server system type.

FunctionDescriptionTutorial
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 functions

Tune timeouts and behavior, and send raw or server-specific FTP commands.

FunctionDescriptionTutorial
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

PHP FTP functions are the ftp_* functions that turn a script into an FTP client. They connect to a server, log in, transfer files, work with remote directories, and send raw FTP commands. All of them take the connection returned by ftp_connect() or ftp_ssl_connect() as the first argument.
The FTP page teaches the ideas: the connect, login, and passive-mode flow, uploading and downloading, directories, and plain FTP versus SSL. This index lists every function tutorial so you can open ftp_put(), ftp_get(), ftp_nlist(), and the rest.
Call ftp_connect() (or ftp_ssl_connect() for encryption), then ftp_login(), then ftp_pasv($ftp, true). After that you can upload with ftp_put(), download with ftp_get(), or list files with ftp_nlist().
Use ftp_nb_get(), ftp_nb_put(), ftp_nb_fget(), and ftp_nb_fput() for large files when you want your script to keep working, for example to show progress. Start the transfer, then call ftp_nb_continue() in a loop until it stops returning FTP_MOREDATA.
No. ftp_quit() is an alias of ftp_close(). Both end the FTP session, so use whichever name you prefer.
If you are new, read PHP FTP first. Then open ftp_connect(), ftp_login(), and ftp_put() from the tables below.

Start with ftp_alloc()

Open the first guide—syntax, examples, and FAQs.

ftp_alloc() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful