How to Transfer Data From or To a Server in Linux

The curl command in Linux is a powerful tool for transferring data from or to a server using various protocols such as HTTP, HTTPS, FTP, and more. It is widely used for testing APIs, downloading files, and performing network operations.

Alby Andersen

The curl command in Linux is a versatile tool for transferring data to or from a server. It supports a wide range of protocols, including HTTP, HTTPS, FTP, and more. Below are practical examples to master curl:


Download a File

curl -O https://example.com/file.zip  
  • -O: Saves the file with its original name.

Download and Save with a Custom Name

curl -o custom_name.zip https://example.com/file.zip  
  • -o: Saves the file as custom_name.zip.

Follow Redirects

curl -L https://example.com  
  • -L: Follows HTTP redirects.

Download Multiple Files

curl -O https://example.com/file1.zip -O https://example.com/file2.zip  


Downloads multiple files in sequence.


Resume an Interrupted Download

curl -C - -O https://example.com/large_file.iso  
  • -C -: Resumes a partially downloaded file.

Send a POST Request with Data

curl -X POST -d "param1=value1&param2=value2" https://example.com/api  
  • -X POST: Specifies the HTTP method.
  • -d: Sends data in the request body.

Send a POST Request with JSON Data

curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://example.com/api  
  • -H: Adds a header (Content-Type: application/json).
  • -d: Sends JSON data.

Send a GET Request with Headers

curl -H "Authorization: Bearer token" https://example.com/api  
  • -H: Adds a custom header (Authorization: Bearer token).

Download Files via FTP

curl -u username:password -O ftp://example.com/file.zip  
  • -u: Authenticates with the FTP server.

Upload a File via FTP

curl -u username:password -T file.zip ftp://example.com/  
  • -T: Uploads file.zip to the FTP server.

Limit Download Speed

curl --limit-rate 200K -O https://example.com/large_file.iso  
  • --limit-rate 200K: Limits the download speed to 200 KB/s.

Display Response Headers Only

curl -I https://example.com  
  • -I: Fetches only the HTTP headers.

Save Cookies to a File

curl -c cookies.txt https://example.com  
  • -c: Saves cookies to cookies.txt.

Use Cookies from a File

curl -b cookies.txt https://example.com  
  • -b: Sends cookies from cookies.txt.

Send a PUT Request

curl -X PUT -d "param1=value1" https://example.com/api  
  • -X PUT: Specifies the HTTP method.

Send a DELETE Request

curl -X DELETE https://example.com/api/resource  
  • -X DELETE: Sends a DELETE request.

Download a File with Authentication

curl -u username:password -O https://example.com/file.zip  
  • -u: Authenticates with the server.

Download a File with a Progress Bar

curl -# -O https://example.com/large_file.iso  
  • -#: Displays a progress bar during the download.

Key Notes:

  • Protocols: curl supports HTTP, HTTPS, FTP, FTPS, SCP, SFTP, and more.
  • Data Transfer: Use -d for sending data and -T for uploading files.
  • Authentication: Use -u for basic authentication or -H for token-based authentication.
Share This Article