Curl Command to Download File from FTP Server
Using the curl command-line tool is one of the most
efficient ways to transfer data to or from a remote server. This article
provides a quick and direct guide on how to use curl to
download a file from an FTP server, covering basic downloads, handling
authentication, and saving files under custom names.
Basic FTP Download
To download a file from a public FTP server and save it with its
original filename, use the -O (uppercase ‘O’) option. This
option tells curl to write the output to a local file named
like the remote file.
curl -O ftp://example.com/directory/filename.txtFTP Download with Authentication
Most FTP servers require a username and password to grant access. You
can pass these credentials using the -u option followed by
the username:password format.
curl -u username:password -O ftp://example.com/directory/filename.txtAlternatively, if you do not want your password to be visible in your
shell history, you can provide only the username. curl will
then prompt you to enter the password securely:
curl -u username -O ftp://example.com/directory/filename.txtDownload and Rename the File
If you want to save the downloaded file under a different name
locally, use the -o (lowercase ‘o’) option followed by the
desired local filename.
curl -u username:password -o local_new_name.txt ftp://example.com/directory/remote_filename.txtDownloading from FTPS (Secure FTP)
If the server requires an encrypted connection (FTPS), change the
protocol in the URL from ftp:// to
ftps://.
curl -u username:password -O ftps://example.com/directory/filename.txt