Uploading files over HTTP POST, multipart forms, or FTP is common. cURL supports these methods and simplifies file transfers, whether for images, documents, or binary data.
By using --form, files can be sent as multipart/form-data. For raw transfers or FTP, cURL manages content types and authentication automatically.
Mastering file uploads with cURL aids integration with APIs, web services, and remote servers. Automation and scripting reduce manual effort and enable rapid development workflows.
Steps to upload files using cURL:
- Open a terminal.
- Upload a file using a form-based POST request.
$ curl --form "file=@/path/to/yourfile.txt" "https://www.example.com/upload" { "status": "uploaded" }
--form sends files as multipart/form-data.
- Upload multiple files by specifying multiple --form options.
$ curl --form "file1=@/path/to/file1.txt" --form "file2=@/path/to/file2.jpg" "https://www.example.com/upload"
Repeat --form for each file.
- Upload a file over FTP using --upload-file and --user.
$ curl --upload-file "/path/to/yourfile.txt" "ftp://ftp.example.com" --user username:password
Authenticate as needed for FTP transfers.
- Include additional form data along with the file.
$ curl --form "file=@/path/to/yourfile.txt" --form "description=Test upload" "https://www.example.com/upload"
Add metadata to simulate complex forms.
- Verify success by reviewing the response.
$ curl --form "file=@/path/to/yourfile.txt" "https://www.example.com/upload" --verbose
--verbose confirms the request and server response.

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.