当前位置:网站首页>如何使用 wget 和 curl 下载文件
如何使用 wget 和 curl 下载文件
2022-07-04 16:32:00 【华为云】
通常使用 wget 来下载文件。在某些系统上,没有安装 wget,只有 curl 可用。能用一个简单的例子来解释我如何使用 curl 下载远程文件吗?curl和wget之间有什么区别吗?
在高层次上,wget 和 curl 都是执行相同操作的命令行实用程序。
- 它们都可用于使用 FTP 和 HTTP(s) 下载文件。
- 您还可以使用 curl 和 wget 发送 HTTP POST 请求
- 但是 curl 提供了可供程序员在自己的代码中使用的 API。curl 使用 libcurl,它是一个跨平台库。
- wget 只是一个没有任何 API 的命令行工具。
- Curl 还支持更多 wget 不支持的协议。例如:SCP、SFTP、TFTP、TELNET、LDAP(S)、文件、POP3、IMAP、SMTP、RTMP 和 RTSP。
- 使用 wget 有一个主要优点。wget 支持递归下载,而 curl 不支持。
wget 示例
以下示例下载文件并以与远程服务器相同的名称存储。
wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2以下示例下载文件并以与远程服务器不同的名称存储。当远程 URL 不包含 url 中的文件名时,这很有用,如下例所示。
wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701卷曲示例
$ curl -O http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 28 3762k 28 1085k 0 0 72771 0 0:00:52 0:00:15 0:00:37 54267选项 -O(大写 O)很重要。没有这个,curl 将开始将下载的文件转储到标准输出上。使用 -O,它会下载与远程服务器同名的文件。在上面的例子中,我们正在下载 strx25-0.9.2.1.tar.bz2,所以下载的文件也将是同名的。
除了 -O,您还可以指定“--remote-name”,如下所示。两者都是一样的。
$ curl --remote-name http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2在 curl 下载时,它会提供以下有用信息:
- % – 截至目前已完成下载的总百分比。当它达到 100% 时,下载完成。在上面的例子中,它只下载了 28% 的文件。
- Total – 文件的总大小
- Received - 到目前为止已下载的文件的总大小。在上面的例子中,到目前为止它已经下载了 1085k(总共 3762k)
- Xferd – 这将在您将一些文件上传到远程服务器时使用。在上传期间,这将指示到目前为止已上传的文件的总大小。因为我们正在下载一个文件,在这个例子中,这是 0。
- Average Speed Dload – 这表示平均下载速度。
- AVerage Speed Upload – 上传文件时,这将指示平均上传速度
- Time Total – 这表示根据当前下载(或上传)速度下载(或上传)整个文件所需的总时间。在此示例中,下载此文件总共需要大约 52 秒。
- Time Spend – curl 到目前为止下载(或上传)文件所花费的时间。在这个例子中,到目前为止它已经花费了 15 秒。
- Time Left –这是根据“总时间”——“所用时间”计算得出的。
- Current Speed – - 这表示当前的下载/上传速度。将此与平均加速 Dload/UPload 进行比较,以查看您的系统当前下载的速度有多快或多慢。
如果要下载文件并将其存储在与远程服务器中文件名不同的名称中,请使用 -o(小写 o),如下所示。当远程 URL 不包含 url 中的文件名时,这很有用,如下例所示。
$ curl -o taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 50243 100 50243 0 0 170k 0 --:--:-- --:--:-- --:--:-- 400k在上面的例子中,远程 URL 中没有文件名,它只是调用了一个 php 脚本,将一些参数传递给它。但是,该文件将被下载并保存为本地系统上的 taglist.zip。代替 -o,您还可以指定“–output”。
边栏推荐
- 【每日一题】556. 下一个更大元素 III
- [Huawei HCIA continuous update] SDN and FVC
- Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
- I wrote a learning and practice tutorial for beginners!
- 为啥有些线上演唱会总是怪怪的?
- 庆贺!科蓝SUNDB与中创软件完成七大产品的兼容性适配
- [unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
- Implementation of shell script replacement function
- "In Vietnam, money is like lying on the street"
- General environmental instructions for the project
猜你喜欢

Load test practice of pingcode performance test

To sort out messy header files, I use include what you use

Blue bridge: sympodial plant

TCP waves twice, have you seen it? What about four handshakes?

Detectron2 installation method

Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt

Ks007 realizes personal blog system based on JSP

7 RSA Cryptosystem

Talk about seven ways to realize asynchronous programming

Recast of recastnavigation
随机推荐
Android uses sqliteopenhelper to flash back
The controversial line of energy replenishment: will fast charging lead to reunification?
Summary of subsidy policies across the country for dcmm certification in 2022
The top half and bottom half of the interrupt are introduced and the implementation method (tasklet and work queue)
With an estimated value of 90billion, the IPO of super chip is coming
Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)
2022年DCMM认证全国各地补贴政策汇总
Cocoscreator event dispatch use
为啥有些线上演唱会总是怪怪的?
High school physics: force, object and balance
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
uni-app与uviewUI实现仿小米商城app(附源码)
Implementation of shell script replacement function
[daily question] 556 Next bigger element III
LD_ LIBRARY_ Path environment variable setting
Heartless sword Chinese translation of Elizabeth Bishop's a skill
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
Recast of recastnavigation
[HCIA continuous update] overview of WLAN workflow
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"