Bobcares

Download multiple files with cURL – Important things you need to know

by | Sep 20, 2020

The curl command uses to download multiple files at the same time.

That’s why we often get requests from customers to install curl command as part of our Technical Support Services.

Today, we’ll see the uses of curl command and how to use curl command in different ways.

Importance of Curl

Client URL, or cURL, is a library and command-line utility for data transfer through systems. Also, it uses for downloading files from the web.

It supports many protocols including HTTP, HTTPS, TELNET, SCP, FTP, etc, and tends to be installed by default on many Unix-like operating systems.

In a server environment, this command becomes a great option when need to download a file to the local machine.

 

How to download files with cURL

Here, we use the curl command to download a text file from a web server and view its contents, save it locally, and tell curl to follow redirects if files have moved.

1. Fetching remote files- The curl command will fetch a file and display its contents to the standard output.

Let us give it a try by downloading the robots.txt file from bobcares.com:

curl https://www.bobcares.com/robots.txt

We can see the file’s contents displayed on the screen as below.

User-agent: *
Disallow:

sitemap: https://www.bobcares.com/sitemap.xml
sitemap: https://www.bobcares.com/community/main_sitemap.xml.gz
sitemap: https://www.bobcares.com/community/questions_sitemap.xml.gz
sitemap: https://www.bobcares.com/community/users_sitemap.xml.gz

Also, if we curl a URL, then it fetches the resource and displays its contents.

2. Saving Remote Files- Curl command is also used to save the contents after downloading it

To save the remote file to the local system, we add the –remote-name argument or use the -O option with the filename that needs to be downloaded.

curl -O https://www.bobcares.com/robots.txt
[secondary_label Output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 286 0 286 0 0 5296 0 --:--:-- --:--:-- --:--:-- 5296

Instead of displaying the contents of the file, it displays a text-based progress meter and saves the file to the same name as the remote file’s name. This can check with the cat command:

cat robots.txt

The file contains the same contents you saw previously:

Now, let us look at specifying a filename for the downloaded file.

3. Saving Remote Files with a Specific File Name- We can use the -o or –output argument, followed by the name of the local file that would like to save the contents. This helps to avoid overwriting the local file of the same name.

Execute the following command to download the remote robots.txt file to the locally named do-bots.txt file:

curl -o do-bots.txt https://www.bobcares.com/robots.txt

 

4. Following Redirects

By default, curl does not follow redirects, so when files move, it does not work as we expect.

For example, if we run the curl command without any protocol, it does not show any output, because Bobcares redirects requests from http:// to https://.

curl -I www.bobcares.com

The output tells that the URL redirected.

[secondary_label Output
HTTP/1.1 301 Moved Permanently
Date: Wed, 26 Aug 2020 19:01:33 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Wed, 26 Aug 2020 20:01:33 GMT
Location: https://www.bobcares.com/robots.txt
cf-request-id: 04cdbea7a40000c5cc8d34d200000001
Server: cloudflare
CF-RAY: 5c8fcd52aea0c5cc-EWR

So, the use of the –location or -L argument solves the issue. It tells curl to redo the request to the new location whenever it encounters a redirect.

curl -L www.bobcares.com/robots.txt

In addition, we can use the argument -L with some of the aforementioned arguments to download the file to the local system:

curl -L -o do-bots.txt www.bobcares.com/robots.txt

 

Downloading multiple files with curl

Basically, instead of downloading multiple files one by one, we can download all of them simultaneously by running a curl command.

For that, we use the following syntax.

curl -O [URL1] -O [URL2]

Also, we can download multiple files from the FTP server using the Curl command. For that, we run the below command.

curl -u ftp_user:ftp_pass -O ftp://ftp_url/file_name.zip

 

Conclusion

In short, curl let’s download files simultaneously from a remote system. Today, we saw how our Support Engineers download multiple files using curl utility.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF