How To Upload A File With curl | Warp

Introducing Warp Factories: open, flexible infrastructure for building your own cloud software factory. Learn More

The short answer

To upload a file with curl using the HTTP POST method, you can use the -F flag (short for --form) with the following syntax:

Bash

$ curl -F "<form_field>=@<local_file_path>" <upload_url>

Where:

For example:

Bash

$ curl -F "file=@mydocument.pdf" https://example.com/upload

This command sends an HTTP POST request to https://example.com/upload with a form field named file containing the contents of the file mydocument.pdf, while setting the Content-Type header to multipart/form-data.

Note that this method is typically used for uploading files via HTTP or HTTPS, and not for FTP or SFTP transfers, which are covered below.

You can learn more about cURL with our other articles on how to send HTTP POST requests with cURL and how to set HTTP headers with cURL.

Easily retrieve this command using Warp’s AI Command Suggestions

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Entering curl upload file in the AI Command Suggestions will prompt a curl command that can then quickly be inserted into your shell by doing CMD+ENTER.

Uploading a file with curl using HTTP PUT

To upload a file using the HTTP PUT method, you can use the curl command with the -T flag (short for --upload-file) as follows:

Bash

$ curl -T <local_file_path> <upload_url>

Where:

For example:

Bash

$ curl -T ./mydocument.txt https://example.com/upload

This command sends an HTTP PUT request to https://example.com/upload with the specified file as the message body of the request.

Uploading a file to an FTP server

To upload a file to an FTP server with curl, you can use the following syntax:

Bash

$ curl -T <local_file_path> -u <username>:<password> ftp://<ftp_server_url>/<remote_directory>/

Where:

For example:

Bash

$ curl -T ./mydocument.txt -u myuser:mypassword ftp://ftp.example.com/uploads/

Note that you should ensure proper permissions and the existence of the remote directory on the FTP server before proceeding. If security is a concern, consider using secure FTP (SFTP) or other encryption methods, as plain FTP transfers data without encryption.

Uploading a file to an SFTP server

To upload a file to an SFTP server with curl, you can use this command syntax:

Bash

$ curl -T <local_file_path> sftp://<username>@<sftp_server_url>/<remote_directory>/

Where:

For example:

Bash

$ curl -T ./mydocument.txt sftp://myuser@sftp.example.com/uploads/

Uploading a file to Artifactory

To upload a file to Artifactory with curl, you can use the following command syntax:

Bash

$ curl -u <username>:<password> -T "<local_file_path>" "<artifactory_url>/artifactory/<repository>/<target_path>/<filename>"

Where:

For example:

Bash

$ curl -u myuser:mypassword -T myartifact.jar "https://artifactory.example.com/artifactory/myrepo/myfolder/myartifact.jar"

Uploading a file to an S3 bucket using a presigned URL

To upload a file to an Amazon S3 bucket with curl using a presigned URL, you can use the following command syntax:

Bash

$ curl --upload-file <local_file_path> <presigned_url>

Where:

For example:

Bash

$ curl --upload-file ./mydocument.pdf "https://s3.amazonaws.com/mybucket/myobject?AWSAccessKeyId=YOUR_ACCESS_KEY&Expires=EXPIRATION_TIMESTAMP&Signature=SIGNATURE"

This command sends a PUT request to the presigned URL with the specified file as the request body.

Uploading a file on Windows

To upload a file on a Windows operating system with curl, you can use a command similar to the ones provided earlier, with adjustments for Windows file paths.

Here's the general command structure:

Bash

$ curl -F "<form_field>=@C:\path\to\local\file" <upload_url>

Where:

For example:

Bash

$ curl -F "file=@C:\Users\Username\Documents\mydocument.pdf" https://example.com/upload