Using cURL for FTP and SFTP transfers enables scripted uploads, downloads, and directory listings without interactive clients. Automating file movement in this way supports scheduled jobs, integration with build pipelines, and quick ad‑hoc transfers using a single, consistent command-line tool. Choosing between plain FTP and encrypted SFTP balances convenience and security based on the data and network environment.
The cURL command encodes the protocol, host, and path directly in the URL, such as ftp://ftp.example.com/public_html/ or sftp://sftp.example.com/home/user/. Options like --upload-file, --remote-name, and --continue-at control how files move between the local system and the remote server, while --user and key options supply credentials for authentication. The same syntax pattern applies across supported platforms, which keeps usage consistent on Linux, macOS, and Windows terminals.
Plain FTP exposes credentials and data in clear text, so it suits only non-sensitive content on trusted networks, whereas SFTP wraps traffic inside SSH with strong encryption. Firewalls, proxies, and server configuration can affect which protocol and ports are reachable, and large or unstable transfers often benefit from resume support rather than starting again from byte zero. Switching between FTP and SFTP typically involves changing only the URL scheme and authentication flags.
Steps to use cURL with FTP and SFTP:
- Open a terminal session in an environment where cURL can reach the target FTP or SFTP server.
- Upload a file to an FTP directory using basic authentication.
$ curl --upload-file example.txt "ftp://ftp.example.com/public_html/" --user username:password % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 123 0 0 100 123 900 0 --:--:-- --:--:-- --:--:-- 1500 226 Transfer complete ##### snipped #####FTP transfers, including --user credentials and file contents, travel unencrypted and can be intercepted on untrusted networks.
- Download a file from an FTP directory while preserving the remote filename.
$ curl --remote-name "ftp://ftp.example.com/public_html/example.txt" --user username:password % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1024 100 1024 0 0 3200 0 --:--:-- --:--:-- --:--:-- 4000 ##### snipped #####--remote-name stores the file using the server-side name instead of requiring a local filename argument.
- List the contents of an FTP directory to confirm paths before transferring files.
$ curl "ftp://ftp.example.com/public_html/" --user username:password drwxr-xr-x 3 user group 4096 Jan 01 12:00 . drwxr-xr-x 5 user group 4096 Jan 01 11:50 .. -rw-r--r-- 1 user group 1024 Jan 01 12:00 example.txt ##### snipped #####
Directory listings reveal exact filenames, sizes, and timestamps, which helps avoid typos and accidental overwrites.
- Upload a file securely to an SFTP home directory using password authentication.
$ curl --upload-file example.txt "sftp://sftp.example.com/home/user/" --user username:password % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 123 0 0 100 123 850 0 --:--:-- --:--:-- --:--:-- 1600 ##### snipped #####SFTP uses the same username and password concept as SSH while encrypting both credentials and data in transit.
- Download a file from an SFTP directory using the same URL pattern as FTP.
$ curl --remote-name "sftp://sftp.example.com/home/user/example.txt" --user username:password % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1024 100 1024 0 0 3000 0 --:--:-- --:--:-- --:--:-- 4200 ##### snipped #####Reusing the same flags and layout across FTP and SFTP reduces mistakes when switching protocols.
- List files on an SFTP directory to inspect remote content and confirm transfer locations.
$ curl "sftp://sftp.example.com/home/user/" --user username:password drwxr-xr-x 4 user user 4096 Jan 01 12:05 . drwxr-xr-x 3 user user 4096 Dec 31 18:00 .. -rw-r--r-- 1 user user 1024 Jan 01 12:00 example.txt ##### snipped #####
Listing the directory after uploads confirms that files landed in the intended path with the expected ownership.
- Resume a partial FTP download instead of restarting from the beginning when supported by the server.
$ curl --continue-at - --remote-name "ftp://ftp.example.com/public_html/example.txt" --user username:password ** Resuming transfer from byte position 512 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1024 100 512 0 0 2900 0 --:--:-- --:--:-- --:--:-- 3900 ##### snipped #####Resuming requires a matching partial local file; mismatched content produces corrupted downloads that often fail checksum or integrity tests.
- Upload a file over SFTP using existing SSH key material instead of a password.
$ curl --upload-file example.txt "sftp://sftp.example.com/home/user/" --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub --user username Enter passphrase for key '/home/user/.ssh/id_rsa': % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 123 0 0 100 123 900 0 --:--:-- --:--:-- --:--:-- 1550 ##### snipped #####Key-based authentication keeps passwords out of scripts and reuses the same OpenSSH keys employed for interactive SSH logins.
- Verify successful transfers by listing the remote SFTP directory again and checking for the expected filenames.
$ curl "sftp://sftp.example.com/home/user/" --user username drwxr-xr-x 4 user user 4096 Jan 01 12:10 . drwxr-xr-x 3 user user 4096 Dec 31 18:00 .. -rw-r--r-- 1 user user 1024 Jan 01 12:00 example.txt ##### snipped #####
Reliable success signals include completed progress meters without errors and the presence of transferred files in directory listings with the correct size.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
