Terminus by Warp
Upload Files With curl

Upload Files With curl

Utsav Poudel
Utsav Poudel

The short answer

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

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

Where:

  • [.inline-code]form_field[.inline-code] is the name of the form field that will receive the file.
  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]upload_url[.inline-code] is the URL where you want to send the file.

For example:

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

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

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-recall-with-ai]Easily retrieve this command using Warp’s AI Command Suggestions[#easily-recall-with-ai]

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

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

[#upload-a-file-via-put]Uploading a file with [.inline-code]curl[.inline-code] using HTTP PUT[#upload-a-file-via-put]

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

$ curl -T <local_file_path> <upload_url>

Where:

  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]upload_url[.inline-code] is the URL where you want to send the file using the PUT method.

For example:

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

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

[#upload-a-file-via-ftp]Uploading a file to an FTP server[#upload-a-file-via-ftp]

To upload a file to an FTP server with [.inline-code]curl[.inline-code], you can use the following syntax:

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

Where:

  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]username[.inline-code] is your FTP username.
  • [.inline-code]password[.inline-code] is your FTP password.
  • [.inline-code]ftp_server_url[.inline-code] is the URL of the FTP server you want to connect to.
  • [.inline-code]remote_directory[.inline-code] is the directory on the FTP server where you want to upload the file.

For example:

$ 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.

[#upload-a-file-via-sftp]Uploading a file to an SFTP server [#upload-a-file-via-sftp]

To upload a file to an SFTP server with [.inline-code]curl[.inline-code], you can use this command syntax:

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

Where:

  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]username[.inline-code] is your SFTP username.
  • [.inline-code]sftp_server_url[.inline-code] is the URL of the SFTP server you want to connect to.
  • [.inline-code]remote_directory[.inline-code] is the directory on the SFTP server where you want to upload the file.

For example:

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

[#upload-a-file-to-artifactory] Uploading a file to Artifactory [#upload-a-file-to-artifactory]

To upload a file to Artifactory with [.inline-code]curl[.inline-code], you can use the following command syntax:

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

Where:

  • [.inline-code]username[.inline-code] is your Artifactory username.
  • [.inline-code]password[.inline-code] is your Artifactory password.
  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]artifactory_url[.inline-code] is the URL of your Artifactory instance.
  • [.inline-code]repository[.inline-code] is the name of the repository where you want to store the file.
  • [.inline-code]target_path[.inline-code] is the optional directory path within the repository where you want to place the file.
  • [.inline-code]filename[.inline-code] is the name you want to give to the uploaded file.

For example:

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

[#upload-a-file-to-aws-s3]Uploading a file to an S3 bucket using a presigned URL[#upload-a-file-to-aws-s3]

To upload a file to an Amazon S3 bucket with [.inline-code]curl[.inline-code] using a presigned URL, you can use the following command syntax:

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

Where:

  • [.inline-code]local_file_path[.inline-code] is the path to the local file you want to upload.
  • [.inline-code]presigned_url[.inline-code] is the presigned URL generated for your S3 bucket and object, which includes authentication and expiration information.

For example:

$ 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.

[#upload-a-file-to-windows]Uploading a file on Windows[#upload-a-file-to-windows]

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

Here's the general command structure:

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

Where:

  • [.inline-code]form_field[.inline-code] is the name of the form field that will receive the file.
  • [.inline-code]C:\path\to\local\file[.inline-code] is the Windows file path to the local file you want to upload.
  • [.inline-code]upload_url[.inline-code] is the URL where you want to send the file.

For example:

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

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.