cURL transfers files over FTP or SFTP. While FTP is unencrypted and suitable for non-sensitive data, SFTP uses SSH for secure encryption, protecting credentials and content.
Specify the protocol in the URL and provide credentials to upload, download, or list files. Choosing FTP or SFTP accommodates various environments, balancing simplicity and security.
SFTP ensures encryption, suitable for sensitive data, while FTP might suffice in controlled networks. Switching protocols involves adjusting the URL and authentication options.
Steps to use cURL with FTP and SFTP:
- Upload a file to FTP.
$ curl --upload-file example.txt "ftp://ftp.example.com/public_html/" --user username:password
--upload-file and --user authenticate and transfer files.
- Download a file from FTP.
$ curl --remote-name "ftp://ftp.example.com/public_html/example.txt" --user username:password
--remote-name saves the file locally with the same name.
- List files on FTP.
$ curl "ftp://ftp.example.com/public_html/" --user username:password
Review directories and files before transfers.
- Upload a file to SFTP securely.
$ curl --upload-file example.txt "sftp://sftp.example.com/home/user/" --user username:password
SFTP uses SSH for encryption.
- Download a file from SFTP.
$ curl --remote-name "sftp://sftp.example.com/home/user/example.txt" --user username:password
Same syntax as FTP, just change protocol to sftp.
- List files on SFTP.
$ curl "sftp://sftp.example.com/home/user/" --user username:password
Ensure necessary permissions and keys are configured.
- Resume a partial FTP download with --continue-at -.
$ curl --continue-at - --remote-name "ftp://ftp.example.com/public_html/example.txt" --user username:password
Resume is possible if the server supports partial requests.
- Use a private key for SFTP.
$ curl --upload-file example.txt "sftp://sftp.example.com/home/user/" --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub --user username
Key-based authentication avoids passwords.

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.