How to Upload a File to FTP Using cURL
This article provides a quick and straightforward guide on how to use the cURL command-line tool to upload files to an FTP server. You will learn the basic syntax for standard FTP uploads, how to handle secure FTPS transfers, and how to include user authentication credentials in your commands.
Basic FTP Upload Syntax
To upload a local file to an FTP server, use the -T (or
--upload-file) option followed by the path of the file you
want to upload, and specify the destination FTP URL.
curl -T filename.txt ftp://example.com/target-directory/Uploading with Authentication
Most FTP servers require a username and password. You can provide
these credentials using the -u (or --user)
option:
curl -T filename.txt ftp://example.com/target-directory/ -u username:passwordIf you prefer not to leave your password in the shell history, you can enter just the username. cURL will securely prompt you to type the password:
curl -T filename.txt ftp://example.com/target-directory/ -u usernameRenaming the File During Upload
To rename the file during the transfer process, specify the new filename at the end of the destination URL path:
curl -T local-file.txt ftp://example.com/target-directory/new-name.txt -u username:passwordUploading via Secure FTP (FTPS)
To secure your data transfer using FTPS (FTP over SSL/TLS), change
the protocol prefix in the URL from ftp:// to
ftps://:
curl -T filename.txt ftps://example.com/target-directory/ -u username:passwordIf the server uses a self-signed SSL certificate and you need to
bypass verification, add the -k (or
--insecure) flag:
curl -k -T filename.txt ftps://example.com/target-directory/ -u username:passwordUploading Multiple Files
You can upload multiple files in a single command by enclosing the filenames in curly braces separated by commas:
curl -T "{file1.txt,file2.txt}" ftp://example.com/target-directory/ -u username:password