Linux curl command examples – Part 2

Linux-Curl-Command-Examples-Part2

Curl, as we know, is very useful command line utility & is used to download/upload data from/onto server. We have already discussed “Curl with some examples in part 1” of the tutorial. In this 2nd part of the tutorial, we will discuss further uses of curl with some examples.

Example:1 Using proxy to download a file

If we are using a proxy server in our environment to have access to internet, then we need to provide information of the proxy server while downloading a file using curl command. To provide the proxy information, option used will be ‘-x’ ,

Example

$ curl -x proxy.server.com:3128 download_URL

Example:2 Limit data transfer rate

When downloading files, we might want to limit the download speed for the downloads as the download might end up using whole bandwidth of the network & thus leaving no speed for other systems on our network. With curl, we have option to limit the download speed & to do so the option used is ‘–limit-rate‘.

Example

$ curl --limit-rate 1024B -O download_URL

Example:3 Download file modified before or after a given date

Curl also provides us with option of downloading  files that were changed before or after the provided date, option used is ‘-z‘.

For example, if we want download files that have been modified after 1st Jan,2017 from a website, the complete command would be

$ curl -z 1-Jan-17 download_URL

Now if we would like to download files that have been modified before 1st jan,2017 from a website, the complete command would be

$ curl -z -1-Jan-17 download_URL

Example:4 Download file after authenticating

There are many websites which only allows the download of a file once the download has been authenticated & authorized. To download such a file using curl, we will use ‘-u‘ option,

Example

$ curl -u username:password download_URL

Example:5 Resume a download

Sometimes it happens during downloading files especially when downloading big files, that we need to stop the download to save bandwidth to carry out some other important task or our download might get interrupted due to some network issue. So rather than start downloading the file all the way from top, we can use ‘-C‘ option with curl to start the download from the point where it was interrupted or stopped,

Example

$ curl -C download_URL

Example:6 Download files from FTP server

Curl supports a number of protocols & FTP is among those protocols. So to download a file from ftp , complete command is

$ curl -u ftpuser:password -O ftp://ftp_pub/public_html/index.html

Example:7 Upload files onto ftp server

We can also upload files to ftp servers suing,

$ curl -u ftpuser:password -T linuxtechi.txt ftp://ftp_pub/public_html/

To upload multiple files, we can use

$ curl -u ftpuser:password -T "(linuxtechi1.txt linuxtechi2.txt)"  ftp://ftp_pub/public_html/

Example:8 Deleting files from ftp server 

With curl, we can also remove files from a FTP server. The command to delete a file from ftp server  is

$ curl ftp://ftp_pub/public_html -X 'DELE linuxtechi.zip' --user ftpuser:password

Example:9 Verifying SSL certificate

We might need to verify the SSL certificate of the website from where we are downloading data. We can do so by using ‘-carcert‘ option with curl command, we also need to provide the name of the certificate that we need to verify,

Example

$ curl --cacert new-ca.crt download_URL

Example:10 Ignoring the ssl certificate warning

When using a website that might be hosted with a self signed certificate, we get a SSL certificate warning message. To ignore this message & continue forward to download, we use ‘-k‘  option in curl,

Example

$ curl -k download_url

These were some uses of curl command with examples, please feel free to share your comments & queries using the comment box below.

2 Responses

  1. manuel says:

    Excellent and impeccable contribution to the community, thousand thanks !!!!!

  2. linuxuser says:

    thanks again and always… Excellent, keep going !

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest