# Wget

**Wget** 是 GNU 项目的一个自由、非交互式命令行工具，用于通过 HTTP、HTTPS、FTP 和 FTPS 获取文件，包括通过 HTTP 代理进行获取，其设计目标是从脚本、cron 任务和终端中调用，无需 X Window 支持。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup><sup> • </sup><sup>[2](http://www.fsf.org/software/wget/wget.html)</sup> 由于它在没有用户在场的情况下运行，因此可以在用户未登录时于后台工作。<sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup> Wget 还为在缓慢或不稳定连接上的稳健性而构建：它会重试失败的下载，以提高完整获取文件的概率。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | GNU 非交互式下载器，支持 HTTP(S)、FTP(S) 和 HTTP 代理，可从脚本和 cron 使用<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup><sup> • </sup><sup>[2](http://www.fsf.org/software/wget/wget.html)</sup> |
| 递归获取 | 对链接的 HTML、XHTML 和 CSS 进行广度优先爬取，默认最大深度 5 层<sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup> |
| 镜像 | `--mirror` 等同于 `-r -N -l inf --no-remove-listing`：递归、时间戳、无限深度<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> |
| 协议范围 | Wget 1.x 支持 HTTP/1.x 和 FTP(S)；Wget2 增加 HTTP/2 和并行传输；两者都不支持 HTTP/3<sup>[4](https://daniel.haxx.se/docs/wcurl-vs-wget.html)</sup> |
| 速率控制 | `--limit-rate=20k` 将获取速度限制为 20 KB/s；`--wait` 在请求之间插入延迟；`--waitretry` 使用线性退避，默认最长 10 秒<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup><sup> • </sup><sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup> |
| 近期版本 | Wget 1.25.0（2024-11-10）修复了 CVE-2024-10524；Wget2 2.3.0 于 2026-09-21 发布<sup>[6](https://www.openwall.com/lists/oss-security/2024/11/18/6)</sup><sup> • </sup><sup>[7](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)</sup> |
| 许可证 | GNU 通用公共许可证，属于 GNU 项目，版权由 FSF 持有<sup>[2](http://www.fsf.org/software/wget/wget.html)</sup><sup> • </sup><sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup> |

## 历史与维护

Wget 可追溯至 1996 年 1 月 9 日的前身，最初由 赫沃耶·尼克希奇（Hrvoje Nikšić）编写。<sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup><sup> • </sup><sup>[2](http://www.fsf.org/software/wget/wget.html)</sup> 它作为 GNU 项目的一部分，在 GNU 通用公共许可证下分发。<sup>[2](http://www.fsf.org/software/wget/wget.html)</sup>

两个主要的项目参考来源在当前维护者名单上存在分歧。GNU/FSF 项目页面称 Wget 由 蒂姆·吕森（Tim Rühsen）、达尔希特·沙阿（Darshit Shah）和朱塞佩·斯克里瓦诺（Giuseppe Scrivano）维护，<sup>[2](http://www.fsf.org/software/wget/wget.html)</sup> 而 [Arch Linux](https://www.edgepedia.org/zh/arch-linux) 手册页则将达尔希特·沙阿和蒂姆·吕森列为维护者，未提及斯克里瓦诺。<sup>[9](https://man.archlinux.org/man/wget.1.en)</sup> 两者都同意沙阿和吕森是维护者。

该项目指定的后继者是 **GNU Wget2**，围绕 libwget 库从零编写，以 GPL 第 3 版或更高版本许可。<sup>[10](https://gitlab.com/gnuwget/wget2/blob/master/README.md)</sup> Wget2 是多线程的，由于 HTTP/2、HTTP 压缩、并行连接以及使用 If-Modified-Since 头，在许多情况下下载速度远快于 Wget 1.x。<sup>[10](https://gitlab.com/gnuwget/wget2/blob/master/README.md)</sup>

## 工作原理

**递归获取。** Wget 可以跟随 HTML、XHTML 和 CSS 页面中的链接，创建远程网站的本地版本，完整重建原始站点的目录结构，同时遵守机器人排除标准（/robots.txt）。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> HTTP 和 HTML 内容的递归获取是广度优先的：深度为 1 的文档先于深度为 2 的文档下载，直到用 `-l` 选项设置的最大深度，其默认值为五层。<sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup> 在源代码层面，递归在 src/recur.c 中的 `retrieve_tree()` 里实现，使用 FIFO URL 队列，逐层下载 URL，而不是沿每条路径走到最大深度。<sup>[11](https://deepwiki.com/mirror/wget/3-url-processing-and-recursive-downloading)</sup>

在获取候选链接之前，Wget 在 src/recur.c 的 `download_child()` 中应用过滤规则，涵盖黑名单、协议方案、域名、`--no-parent`、包含与排除列表、正则表达式、主机跨越以及 robots.txt 检查；robots.txt 合规本身在 src/res.c 中实现。<sup>[11](https://deepwiki.com/mirror/wget/3-url-processing-and-recursive-downloading)</sup>

**链接转换与蜘蛛模式。** `--convert-links`（`-k`）选项会转换已下载文档中的链接，包括可见超链接、嵌入图像和样式表链接，使本地副本适合本地查看。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 使用 `--spider` 时，Wget 表现为一个 Web 蜘蛛，检查页面是否存在而不下载它们。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 指定 HTTP 方法 HEAD 也会自动设置蜘蛛模式，从而不下载任何文件。<sup>[12](https://github.com/mirror/wget/blob/master/src/main.c)</sup>

**重试与时间戳。** Wget 为在不稳定连接上的稳健性而设计，会重试失败的下载，以提高完整获取文件的概率。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 时间戳（`-N`）让镜像只重新获取服务器上已更改的文件，而 `--mirror` 将其与递归结合。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup>

## 关键选项与使用模式

控制镜像或爬取的选项会相互作用，安全的做法是显式限制爬取范围：

- `-r`（`--recursive`）启用递归下载；`-l`/`--level=NUMBER` 设置最大深度，`inf` 或 `0` 表示无限。<sup>[12](https://github.com/mirror/wget/blob/master/src/main.c)</sup>
- `-np`（`--no-parent`）避免从其他目录下载，`--page-requisites` 获取单个页面所需的资源而不进行额外递归。<sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup>
- `--mirror` 开启递归和时间戳，设置无限递归深度，并保留 FTP 目录列表；在 Wget 1.x 中它等同于 `-r -N -l inf --no-remove-listing`。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 在 Wget2 中它目前等同于 `-r -N -l inf`。<sup>[13](https://manpages.debian.org/unstable/wget2/wget2.1.en.html)</sup>
- `--convert-links` 重写链接以供本地查看；`--wait` 指定两次获取之间的秒数，后缀 `m`、`h` 和 `d` 分别表示分钟、小时和天。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup>

**脚本与退出码。** Wget 的非交互式设计正是它适合 cron 任务和 CI 流水线的原因。<sup>[2](http://www.fsf.org/software/wget/wget.html)</sup><sup> • </sup><sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup> 退出码行为随时间发生了实质性变化：在 1.12 之前的版本中，退出状态无用且不一致，递归下载几乎总是返回 0（成功），无论遇到什么问题。<sup>[9](https://man.archlinux.org/man/wget.1.en)</sup> Wget2 后来为空操作调用设置了退出码 1，这一变化对根据状态分支的脚本有影响。<sup>[14](https://gitlab.com/gnuwget/wget2/-/releases/v2.3.0)</sup>

## 数字一览

- 默认最大递归深度：5 层。<sup>[3](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)</sup>
- 默认读取超时：900 秒，不过远程服务器可能更早终止连接。<sup>[9](https://man.archlinux.org/man/wget.1.en)</sup>
- `--waitretry` 使用线性退避，第一次失败后等待 1 秒，第二次后等待 2 秒，默认最长 10 秒。<sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup>
- 读取缓冲区：在 Wget 1.21.4（2023-05-11）中增加到 64k，以加快千兆及更快连接上的下载；该版本还增加了 `--retry-on-host-error`。<sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup>
- `--limit-rate=20k` 将获取速度限制为 20 KB/s；该选项接受带 `k`（千字节）和 `m`（兆字节）后缀的字节数。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 在 Wget2 中，该限制通过在快速网络读取后休眠来实现。<sup>[13](https://manpages.debian.org/unstable/wget2/wget2.1.en.html)</sup>
- 发布日期：Wget 1.24.5 于 2024-03-10，Wget 1.25.0 于 2024-11-10，Wget2 2.3.0 于 2026-09-21。<sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup><sup> • </sup><sup>[6](https://www.openwall.com/lists/oss-security/2024/11/18/6)</sup><sup> • </sup><sup>[7](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)</sup>

## 与 cURL、aria2 和 HTTrack 的比较

与 curl 相比，Wget 的主要优势在于其递归下载能力，甚至只是下载远程资源（无论是 HTML 页面还是 FTP 目录列表）所引用的所有内容。<sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup> 相比之下，curl 由 libcurl 驱动，这是一个具有稳定 API 的跨平台库，而 Wget 仅限命令行，没有库；curl 还支持多得多的协议（SCP、SFTP、MQTT、POP3、IMAP、SMTP、RTSP 等），而 Wget 只支持 HTTP(S) 和 FTP(S)。<sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup> Wget 是 GPL v3，版权转让给 FSF，而 curl 是 MIT 许可且独立；两者都能恢复中断的传输，curl 提供 -C、--continue-at，并使用 -C - 自动确定恢复点；在 curl 出于安全原因放弃 metalink 后，Wget 仍然支持它。<sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup><sup> • </sup><sup>[24](https://curl.se/docs/manpage.html?code=xxx)</sup>

在 Wget 家族内部，Wget 1.x 是一个独立可执行文件，串行下载 URL，仅支持 HTTP/1，默认启用 cookie，并可在 Windows 上运行；Wget2 使用并行传输，也支持 HTTP/2，而两者都不支持 HTTP/3。<sup>[4](https://daniel.haxx.se/docs/wcurl-vs-wget.html)</sup> curl 项目的官方比较表将 Wget 1.25.0、wget2 2.1.0、aria2、lftp、HTTrack、HTTPie 和其他工具并排列出，比较协议、递归和并行性等特性。<sup>[15](https://curl.se/docs/comparison-table.html)</sup>

对脚本环境的一个提醒：[BusyBox](https://www.edgepedia.org/zh/busybox) 中有一个 `wget`，但它不是真正的 Wget，只是一个同名的精简克隆。<sup>[8](https://daniel.haxx.se/docs/curl-vs-wget.html)</sup>

## 安全与负责任的使用

若干漏洞塑造了近期版本。Wget 1.19.5 修复了 cookie 注入漏洞 CVE-2018-0494。<sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup> Wget 1.25.0 放弃了对简写 FTP URL 的支持以修复 CVE-2024-10524，这是一个破坏性变更，同时切换到从 stdin 管道进行连续非阻塞读取（Windows 上不可用），并基于 RFC 2396 重新实现了用户信息解析。<sup>[6](https://www.openwall.com/lists/oss-security/2024/11/18/6)</sup> Wget 1.25.0 中还报告了另外四个漏洞，涉及 Metalink URL 解析器、HTTP Content-Range 头处理、iconv 文件名转换和 HTML 链接转换；iconv 问题需要 `--remote-encoding` 或 IRI 模式，链接转换问题需要递归下载配合 `--convert-links`。<sup>[16](https://www.mail-archive.com/bug-wget@gnu.org/msg10867.html)</sup> CERT VU#564823 记录，在被动模式下通过 FTP 操作时，Wget 依赖服务器的 PASV 响应来确定数据连接 IP 地址和端口而不进行验证，从而可能实现服务端请求伪造。<sup>[17](https://www.kb.cert.org/vuls/id/564823)</sup>

Wget2 有自己的加固周期。CVE-2025-69195 是 Wget2 在文件名限制选项激活时处理攻击者控制的 URL 路径时，文件名清理中的基于栈的缓冲区溢出，影响 2.1.0 至 2.2.0 版本，在 2.2.1 中修复。<sup>[18](https://nvd.nist.gov/vuln/detail/cve-2025-69195)</sup> Wget2 2.2.1 于 2026 年 1 月发布，修复了 metalink 的文件覆盖问题以及 `get_local_filename_real()` 中的远程缓冲区溢出。<sup>[19](https://seclists.org/oss-sec/2026/q1/30)</sup> Wget2 2.3.0 修复了递归解析本地文件时的栈溢出，将最大 XML 递归深度限制为 1024，清理 Metalink Windows 路径以防止路径遍历，清理 Content-Disposition 文件名，并且现在只接受来自 HTTPS 的安全 cookie。<sup>[7](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)</sup> 各发行版已广泛包含这些修复：Ubuntu 的公告 USN-8543-1 更新了从 14.04 到 26.04 各版本的 Wget，包括 26.04 LTS 上的 wget 1.25.0-2ubuntu4.2 和 24.04 LTS 上的 1.21.4-1ubuntu4.3。<sup>[20](https://ubuntu.com/security/notices/USN-8543-1)</sup>

**礼仪。** Wget 自己的文档推荐 `--wait`，因为它通过降低请求频率来减轻服务器负载。<sup>[1](https://man7.org/linux/man-pages/man1/wget.1.html)</sup> 在爬虫文献中，这一同样的义务被广泛描述：爬虫应以“礼貌”对待 Web 服务器，而它们依赖的两个结构——仍待爬取的 URL 前沿和已发现的 URL 集合——通常超出主内存的容量。<sup>[21](https://marc.najork.org/papers/eds2009a.pdf)</sup> 一篇 2024 年 USENIX Security 关于 Web 安全测量爬取算法的系统化知识论文将 GNU Wget 列入其审查的非学术爬取工具之一，与 Arachni、Skipfish、w3af 和 ZAP 并列。<sup>[22](https://www.usenix.org/system/files/usenixsecurity24-stafeev.pdf)</sup>

## 近期发展

在 Wget 1.x 系列上，1.24.5（2024-03-10）修复了 HSTS 子域匹配检查方式，防止 cookie 泄露到错误的域，<sup>[5](https://github.com/mirror/wget/blob/master/NEWS)</sup> 随后 1.25.0（2024-11-10）带来了 CVE-2024-10524 修复以及 stdin 和用户信息解析的更改。<sup>[6](https://www.openwall.com/lists/oss-security/2024/11/18/6)</sup>

Wget2 进展更快。2.2.1 版（2026 年 1 月）提供了上述安全修复以及重定向和镜像回归修复、convert-links 修复，以及使用本地系统时间戳的 `--no-use-server-timestamps`。<sup>[19](https://seclists.org/oss-sec/2026/q1/30)</sup> 2.3.0 版（2026-09-21）增加了 `--progress=dot` 作为默认温度计条的基于文本的替代方案，为 HTTP/2 实现了 1xx 响应跳过，并修复了 `--page-requisites`、`--no-parent` 与 `--level 0`/`--mirror` 的组合问题、`--convert-links` 下的 CSS 处理，以及 `--directory-prefix` 的 wget1.x 兼容性；它还为 POST、PUT 和 PATCH 增加了符合 RFC 9110 的 Content-Length: 0。<sup>[7](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)</sup><sup> • </sup><sup>[14](https://gitlab.com/gnuwget/wget2/-/releases/v2.3.0)</sup> Phoronix 报道 2.3 是 2026 年第一个新的 Wget2 版本，指出其改进了 OS/2 支持，包括 ANSI 转义码、动态加载、类 DOS 路径风格和符号导出。<sup>[23](https://www.phoronix.com/news/GNU-Wget-2.3-Released)</sup>

尽管名字如此，Wget2 覆盖的范围比人们预期的要少：它仅替代原始 wget 的 HTTP 能力，不支持 FTP 和任何其他协议。<sup>[7](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)</sup> 然而，它爬取更多格式：Wget2 可以跟随 HTML、XHTML、CSS、RSS、Atom 和站点地图文件中的链接，创建远程站点的本地版本。<sup>[13](https://manpages.debian.org/unstable/wget2/wget2.1.en.html)</sup> Wget 1.x 手册页本身将用户指向 wget2(1)，称其为 GNU Wget 的更新版本，对递归下载和 HTTP/2 等现代协议有更好的支持。<sup>[9](https://man.archlinux.org/man/wget.1.en)</sup>

## References

1. [wget(1) - Linux manual page (Wget 1.x)](https://man7.org/linux/man-pages/man1/wget.1.html)
2. [Wget - GNU Project - Free Software Foundation](http://www.fsf.org/software/wget/wget.html)
3. [GNU Wget Manual (1.8.1)](http://ftp.ncnu.edu.tw/gnu/pub/old-gnu/Manuals/wget-1.8.1/html_mono/wget.html)
4. [wcurl vs Wget (Daniel Stenberg)](https://daniel.haxx.se/docs/wcurl-vs-wget.html)
5. [wget NEWS (changelog)](https://github.com/mirror/wget/blob/master/NEWS)
6. [oss-security: wget-1.25.0 released [fixes CVE-2024-10524]](https://www.openwall.com/lists/oss-security/2024/11/18/6)
7. [Updated: wget2 2.3 (Cygwin announcement)](https://sourceware.org/pipermail/cygwin-announce/2026-September/013418.html)
8. [curl vs Wget (Daniel Stenberg)](https://daniel.haxx.se/docs/curl-vs-wget.html)
9. [wget(1) - Arch manual pages](https://man.archlinux.org/man/wget.1.en)
10. [GNU Wget2 README (official GitLab repository)](https://gitlab.com/gnuwget/wget2/blob/master/README.md)
11. [URL Processing and Recursive Downloading, DeepWiki (mirror/wget)](https://deepwiki.com/mirror/wget/3-url-processing-and-recursive-downloading)
12. [src/main.c - mirror/wget (GNU Wget source)](https://github.com/mirror/wget/blob/master/src/main.c)
13. [wget2(1) - Debian unstable manpage](https://manpages.debian.org/unstable/wget2/wget2.1.en.html)
14. [Wget2 v2.3.0 release notes (GitLab)](https://gitlab.com/gnuwget/wget2/-/releases/v2.3.0)
15. [curl - Comparison Table](https://curl.se/docs/comparison-table.html)
16. [Vulnerability Report - 4 findings in GNU Wget 1.25.0 (bug-wget mailing list)](https://www.mail-archive.com/bug-wget@gnu.org/msg10867.html)
17. [VU#564823 - GNU Wget enables SSRF via unvalidated FTP PASV IPs (CERT/CC)](https://www.kb.cert.org/vuls/id/564823)
18. [NVD - CVE-2025-69195](https://nvd.nist.gov/vuln/detail/cve-2025-69195)
19. [oss-sec: wget2-2.2.1 released with security fixes](https://seclists.org/oss-sec/2026/q1/30)
20. [USN-8543-1: Wget vulnerabilities (Ubuntu)](https://ubuntu.com/security/notices/USN-8543-1)
21. [Web Crawler Architecture (Marc Najork, 2009)](https://marc.najork.org/papers/eds2009a.pdf)
22. [SoK: State of the Krawlers (USENIX Security 2024)](https://www.usenix.org/system/files/usenixsecurity24-stafeev.pdf)
23. [GNU Wget 2.3 Released (Phoronix)](https://www.phoronix.com/news/GNU-Wget-2.3-Released)
24. [curl - How To Use](https://curl.se/docs/manpage.html?code=xxx)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Build, deployment, and development tooling

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/wget

English original: https://www.edgepedia.org/wget
