当前位置:网站首页>如何使用 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”。
边栏推荐
- ARTS_20220628
- Face_recognition人脸识别之考勤统计
- Large scale service exception log retrieval
- Self reflection of a small VC after two years of entrepreneurship
- Summary of subsidy policies across the country for dcmm certification in 2022
- I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
- Pytorch深度学习之环境搭建
- 一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)
- 无心剑中译伊丽莎白·毕肖普《一门技艺》
- What if Kaili can't input Chinese???
猜你喜欢

Five thousand words to clarify team self-organization construction | Liga wonderful talk

Is it science or metaphysics to rename a listed company?

Weima, which is going to be listed, still can't give Baidu confidence

78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报

Numpy 的仿制 2
![[test development] software testing - Basics](/img/43/514016f270574fe711e0e15b581022.png)
[test development] software testing - Basics

Imitation of numpy 2

Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)

The block:usdd has strong growth momentum

"In Vietnam, money is like lying on the street"
随机推荐
Wuzhicms code audit
我写了一份初学者的学习实践教程!
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
ISO27001 certification process and 2022 subsidy policy summary
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
【Hot100】32. 最长有效括号
大规模服务异常日志检索
用于图数据库的开源 PostgreSQL 扩展 AGE被宣布为 Apache 软件基金会顶级项目
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
7 RSA Cryptosystem
估值900亿,超级芯片IPO来了
Introduction of time related knowledge in kernel
Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
MySQL常用增删改查操作(CRUD)
[HCIA continuous update] WAN technology
"In Vietnam, money is like lying on the street"
Win32 API 访问路由的加密网页
【Hot100】31. 下一个排列
Large scale service exception log retrieval
【210】PHP 定界符的用法