Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to download a file using the curl command

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use curl commands to download files". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use curl commands to download files" can help you solve the problem.

Curl is an open source command line tool and library for data transmission, it uses URL syntax format, supports many transfer protocols, including: HTTP, HTTPS, FTP, FTPS, GOPHER, TFTP, SCP, etc., curl library provides many powerful features, you can use it for HTTP/HTTPS requests, upload / download files, etc., and support Cookie, authentication, agent, speed limit, etc.

Environment

Centos7.7

Download the file to make the name consistent

You can use the same name of the curl download file as the local file name. You can use the-O option.

[root@localhost ~] # curl http://mirrors.163.com/centos/8.1.1911/isos/x86_64/CentOS-8.1.1911-x86_64-dvd1.iso% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed 0 7205M 0 25.9M 00 5452k 00: 22:33 0:00:04 0:22:29 5452k [root@localhost ~] # lsCentOS-8.1.1911-x86_64-dvd1.iso downloads multiple files

When downloading multiple files at the same time, you can use multiple-O flags, followed by a url link.

[root@localhost] # curl-O [URL1]-O [URL2]-O [URL3].

Example:

[root@localhost ~] # curl-O www.example.com/file.pdf-O www.example.com/file1.pdf% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 20597 20597 00 1436k 0 -::-1436k100 20597 100 20597 00 9.8m 0-9.8m

If the files in url have numbers and are in order, you can use regular syntax:

[root@localhost ~] # curl ftp://ftp.example.com/file[1-30].jpg

If you want to save multiple files with different names, you can use the-o option, as shown below.

[root@localhost ~] # curl-o file2.pdf www.example.com/file.pdf-o file3.pdf www.example.com/file1.pdf% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 20597 20597 00 957k 0 -: -:-957k100 20597 20597 00 19.6m 0-19.6m download file shows progress bar

Curl displays a schedule during file download, showing the transfer rate, the amount of data transferred, the remaining time, etc.

[root@localhost] # curl-#-O http://mirrors.163.com/centos/8.1.1911/isos/x86_64/CentOS-8.1.1911-x86_64-dvd1.iso## 3.5% how to limit the maximum transmission speed

The use of limiting the data transfer rate is:

[root@localhost] # curl-- limit-rate [value] [URL]

This value can be expressed in bytes, with the k suffix kilobyte, m suffix megabyte, and g suffix gigabyte.

The following command limits the download speed to 1mb:

[root@localhost ~] # curl-- limit-rate 1m-O http://mirrors.163.com/centos/8.1.1911/isos/x86_64/CentOS-8.1.1911-x86_64-dvd1.iso% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed 0 7205M 0 21.1M 0 01033k 0 1:58:57: 00:20 1:58:37 1005k that's all for "how to download a file using the curl command". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report