【194】Windows 上使用 wget

        本文包括两部分,首先就是在 Windows 使用 wget 来下载文件,这样固然很好,然而问题并非这么简单,在 PowerShell 4.0 版本中增加了 Invoke-WebRequest 的别名 wget,因此在像上面使用 wget 的时候,会首先调用 Invoke-WebRequest,也就出现问题了,解决方法我想到两种,第一种就是修改 wget.exe 文件的名称,第二种就是删除 Invoke-WebRequest 的 wget 别名。

参考:windows 上使用wget

配置步骤:

  1. 从下面链接下载 wget(1.11.4) for win: http://users.ugent.be/~bpuype/wget/ 。
  2. 下载完成后,解压出 wget.exe 文件,把它放到c:windowssytem32目录下。
  3. 直接在 cmd 或者 PowerShell 上面就可以试用了。

解决方案:

  1. 将解压出的 wget.exe 重命名为 wget2.exe,调用的时候直接用 wget2 即可,也可以修改成其他喜欢的名字。
    wget2 -c http://www.download.com/1.txt
    
  2. 删除 Invoke-WebRequest 的别名 wget,代码如下,此方法只在当前会话中起作用,并不会永久删除。
    参考:Powershell 尝试删除所有别名
    Remove-Item -Path Alias:wget -Force
    or
    del alias:wget
  3. 对于写成 *.ps1 文件中需要使用 wget 的时候,可以在代码前加一个上面的代码段,这样就不会影响后续的使用了!

wget 工具帮助:

从 Linux 上拷贝的,可能与 Windows 上用法有点出入,但是是中文版的,后面有 Windows 版的,但是是英文版的!

PS > wget --help
GNU Wget 1.5.3.1, 非交互式下载工具。
用法: wget [选项]... [URL]...

长选项所必须的参数在使用短选项时也是必须的。

开始:
  -V,  --version           显示 Wget 的版本信息并退出。
  -h,  --help              打印此帮助。
  -b,  --background        启动后转入后台。
  -e,  --execute=COMMAND   运行一个‘.wgetrc’风格的命令。

登入并输入文件:
  -o,  --output-file=FILE    将信息写入 FILE。
  -a,  --append-output=FILE  将信息添加至 FILE。
  -d,  --debug               打印大量调试信息。
  -q,  --quiet               安静模式(无信息输出)。
  -v,  --verbose             详尽的输出(此为默认值)。
  -nv, --no-verbose          关闭详尽输出,但不进入安静模式。
  -i,  --input-file=FILE     下载本地或外部 FILE 中的 URLs。
  -F,  --force-html          把输入文件当成 HTML 文件。
  -B,  --base=URL            解析与 URL 相关的
                             HTML 输入文件(由 -i -F 选项指定)。

下载:
  -t,  --tries=NUMBER            设置重试次数为 NUMBER (0 代表无限制)。
       --retry-connrefused       即使拒绝连接也是重试。
  -O,  --output-document=FILE    将文档写入 FILE。
  -nc, --no-clobber              不要重复下载已存在的文件。
                                 
  -c,  --continue                继续下载部分下载的文件。
       --progress=TYPE           选择进度条类型。
  -N,  --timestamping            只获取比本地文件新的文件。
                                 
  -S,  --server-response         打印服务器响应。
       --spider                  不下载任何文件。
  -T,  --timeout=SECONDS         将所有超时设为 SECONDS 秒。
       --dns-timeout=SECS        设置 DNS 查寻超时为 SECS 秒。
       --connect-timeout=SECS    设置连接超时为 SECS 秒。
       --read-timeout=SECS       设置读取超时为 SECS 秒。
  -w,  --wait=SECONDS            等待间隔为 SECONDS 秒。
       --waitretry=SECONDS       在取回文件的重试期间等待 1..SECONDS 秒。
       --random-wait             取回时等待 0...2*WAIT 秒。
       --no-proxy                关闭代理。
  -Q,  --quota=NUMBER            设置取回配额为 NUMBER 字节。
       --bind-address=ADDRESS    绑定至本地主机上的 ADDRESS (主机名或是 IP)。
       --limit-rate=RATE         限制下载速率为 RATE。
       --no-dns-cache            关闭 DNS 查寻缓存。
       --restrict-file-names=OS  限定文件名中的字符为 OS 允许的字符。
       --ignore-case             匹配文件/目录时忽略大小写。
  -4,  --inet4-only              仅连接至 IPv4 地址。
  -6,  --inet6-only              仅连接至 IPv6 地址。
       --prefer-family=FAMILY    首先连接至指定协议的地址
                                 FAMILY 为 IPv6,IPv4 或是 none。
       --user=USER               将 ftp 和 http 的用户名均设置为 USER。
       --password=PASS           将 ftp 和 http 的密码均设置为 PASS。
       --ask-password            提示输入密码。
       --no-iri                  关闭 IRI 支持。
       --local-encoding=ENC      IRI 使用 ENC 作为本地编码。
       --remote-encoding=ENC     使用 ENC 作为默认远程编码。

目录:
  -nd, --no-directories           不创建目录。
  -x,  --force-directories        强制创建目录。
  -nH, --no-host-directories      不要创建主目录。
       --protocol-directories     在目录中使用协议名称。
  -P,  --directory-prefix=PREFIX  以 PREFIX/... 保存文件
       --cut-dirs=NUMBER          忽略 NUMBER 个远程目录路径。

HTTP 选项:
       --http-user=USER        设置 http 用户名为 USER。
       --http-password=PASS    设置 http 密码为 PASS。
       --no-cache              不在服务器上缓存数据。
       --default-page=NAME     改变默认页
                               (默认页通常是“index.html”)。
  -E,  --adjust-extension      以合适的扩展名保存 HTML/CSS 文档。
       --ignore-length         忽略头部的‘Content-Length’区域。
       --header=STRING         在头部插入 STRING。
       --max-redirect          每页所允许的最大重定向。
       --proxy-user=USER       使用 USER 作为代理用户名。
       --proxy-password=PASS   使用 PASS 作为代理密码。
       --referer=URL           在 HTTP 请求头包含‘Referer: URL’。
       --save-headers          将 HTTP 头保存至文件。
  -U,  --user-agent=AGENT      标识为 AGENT 而不是 Wget/VERSION。
       --no-http-keep-alive    禁用 HTTP keep-alive(永久连接)。
       --no-cookies            不使用 cookies。
       --load-cookies=FILE     会话开始前从 FILE 中载入 cookies。
       --save-cookies=FILE     会话结束后保存 cookies 至 FILE。
       --keep-session-cookies  载入并保存会话(非永久) cookies。
       --post-data=STRING      使用 POST 方式;把 STRING 作为数据发送。
       --post-file=FILE        使用 POST 方式;发送 FILE 内容。
       --content-disposition   当选中本地文件名时
                               允许 Content-Disposition 头部(尚在实验)。
       --auth-no-challenge     send Basic HTTP authentication information
                               without first waiting for the server's
                               challenge.

HTTPS (SSL/TLS) 选项:
       --secure-protocol=PR     选择安全协议,可以是 auto、SSLv2、
                                SSLv3 或是 TLSv1 中的一个。
       --no-check-certificate   不要验证服务器的证书。
       --certificate=FILE       客户端证书文件。
       --certificate-type=TYPE  客户端证书类型, PEM 或 DER。
       --private-key=FILE       私钥文件。
       --private-key-type=TYPE  私钥文件类型, PEM 或 DER。
       --ca-certificate=FILE    带有一组 CA 认证的文件。
       --ca-directory=DIR       保存 CA 认证的哈希列表的目录。
       --random-file=FILE       带有生成 SSL PRNG 的随机数据的文件。
       --egd-file=FILE          用于命名带有随机数据的 EGD 套接字的文件。

FTP 选项:
       --ftp-user=USER         设置 ftp 用户名为 USER。
       --ftp-password=PASS     设置 ftp 密码为 PASS。
       --no-remove-listing     不要删除‘.listing’文件。
       --no-glob               不在 FTP 文件名中使用通配符展开。
       --no-passive-ftp        禁用“passive”传输模式。
       --retr-symlinks         递归目录时,获取链接的文件(而非目录)。

递归下载:
  -r,  --recursive          指定递归下载。
  -l,  --level=NUMBER       最大递归深度( inf 或 0 代表无限制,即全部下载)。
       --delete-after       下载完成后删除本地文件。
  -k,  --convert-links      让下载得到的 HTML 或 CSS 中的链接指向本地文件。
  -K,  --backup-converted   在转换文件 X 前先将它备份为 X.orig。
  -m,  --mirror             -N -r -l inf --no-remove-listing 的缩写形式。
  -p,  --page-requisites    下载所有用于显示 HTML 页面的图片之类的元素。
       --strict-comments    开启 HTML 注释的精确处理(SGML)。

递归接受/拒绝:
  -A,  --accept=LIST               逗号分隔的可接受的扩展名列表。
  -R,  --reject=LIST               逗号分隔的要拒绝的扩展名列表。
  -D,  --domains=LIST              逗号分隔的可接受的域列表。
       --exclude-domains=LIST      逗号分隔的要拒绝的域列表。
       --follow-ftp                跟踪 HTML 文档中的 FTP 链接。
       --follow-tags=LIST          逗号分隔的跟踪的 HTML 标识列表。
       --ignore-tags=LIST          逗号分隔的忽略的 HTML 标识列表。
  -H,  --span-hosts                递归时转向外部主机。
  -L,  --relative                  只跟踪有关系的链接。
  -I,  --include-directories=LIST  允许目录的列表。
  --trust-server-names  use the name specified by the redirection url last component.
  -X,  --exclude-directories=LIST  排除目录的列表。
  -np, --no-parent                 不追溯至父目录。

Windows 版的帮助:

PS C:UsersYGS-BNLI-T1> wget2 -h
GNU Wget 1.5.3.1, a non-interactive network retriever.
Usage: wget2 [OPTION]... [URL]...

Mandatory arguments to long options are mandatory for short options too.

Startup:
  -V,  --version           display the version of Wget and exit.
  -h,  --help              print this help.
  -b,  --background        go to background after startup.
  -e,  --execute=COMMAND   execute a `.wgetrc' command.

Logging and input file:
  -o,  --output-file=FILE     log messages to FILE.
  -a,  --append-output=FILE   append messages to FILE.
  -d,  --debug                print debug output.
  -q,  --quiet                quiet (no output).
  -v,  --verbose              be verbose (this is the default).
  -nv, --non-verbose          turn off verboseness, without being quiet.
  -i,  --input-file=FILE      read URL-s from file.
  -F,  --force-html           treat input file as HTML.

Download:
  -t,  --tries=NUMBER           set number of retries to NUMBER (0 unlimits).
  -O   --output-document=FILE   write documents to FILE.
  -nc, --no-clobber             don't clobber existing files.
  -c,  --continue               restart getting an existing file.
       --dot-style=STYLE        set retrieval display style.
  -N,  --timestamping           don't retrieve files if older than local.
  -S,  --server-response        print server response.
       --spider                 don't download anything.
  -T,  --timeout=SECONDS        set the read timeout to SECONDS.
  -w,  --wait=SECONDS           wait SECONDS between retrievals.
  -Y,  --proxy=on/off           turn proxy on or off.
  -Q,  --quota=NUMBER           set retrieval quota to NUMBER.

Directories:
  -nd  --no-directories            don't create directories.
  -x,  --force-directories         force creation of directories.
  -nH, --no-host-directories       don't create host directories.
  -P,  --directory-prefix=PREFIX   save files to PREFIX/...
       --cut-dirs=NUMBER           ignore NUMBER remote directory components.

HTTP options:
       --http-user=USER      set http user to USER.
       --http-passwd=PASS    set http password to PASS.
  -C,  --cache=on/off        (dis)allow server-cached data (normally allowed).
       --ignore-length       ignore `Content-Length' header field.
       --header=STRING       insert STRING among the headers.
       --proxy-user=USER     set USER as proxy username.
       --proxy-passwd=PASS   set PASS as proxy password.
  -s,  --save-headers        save the HTTP headers to file.
  -U,  --user-agent=AGENT    identify as AGENT instead of Wget/VERSION.

FTP options:
       --retr-symlinks   retrieve FTP symbolic links.
  -g,  --glob=on/off     turn file name globbing on or off.
       --passive-ftp     use the "passive" transfer mode.

Recursive retrieval:
  -r,  --recursive             recursive web-suck -- use with care!.
  -l,  --level=NUMBER          maximum recursion depth (0 to unlimit).
       --delete-after          delete downloaded files.
  -k,  --convert-links         convert non-relative links to relative.
  -m,  --mirror                turn on options suitable for mirroring.
  -nr, --dont-remove-listing   don't remove `.listing' files.

Recursive accept/reject:
  -A,  --accept=LIST                list of accepted extensions.
  -R,  --reject=LIST                list of rejected extensions.
  -D,  --domains=LIST               list of accepted domains.
       --exclude-domains=LIST       comma-separated list of rejected domains.
  -L,  --relative                   follow relative links only.
       --follow-ftp                 follow FTP links from HTML documents.
  -H,  --span-hosts                 go to foreign hosts when recursive.
  -I,  --include-directories=LIST   list of allowed directories.
  -X,  --exclude-directories=LIST   list of excluded directories.
  -nh, --no-host-lookup             don't DNS-lookup hosts.
  -np, --no-parent                  don't ascend to the parent directory.

Mail bug reports and suggestions to <bug-wget@gnu.org>.
GNU Wget 1.5.3.1, a non-interactive network retriever.

Usage: wget2 [OPTION]... [URL]...



Mandatory arguments to long options are mandatory for short options too.



Startup:

  -V,  --version           display the version of Wget and exit.

  -h,  --help              print this help.

  -b,  --background        go to background after startup.

  -e,  --execute=COMMAND   execute a `.wgetrc' command.



Logging and input file:

  -o,  --output-file=FILE     log messages to FILE.

  -a,  --append-output=FILE   append messages to FILE.

  -d,  --debug                print debug output.

  -q,  --quiet                quiet (no output).

  -v,  --verbose              be verbose (this is the default).

  -nv, --non-verbose          turn off verboseness, without being quiet.

  -i,  --input-file=FILE      read URL-s from file.

  -F,  --force-html           treat input file as HTML.



Download:

  -t,  --tries=NUMBER           set number of retries to NUMBER (0 unlimits).

  -O   --output-document=FILE   write documents to FILE.

  -nc, --no-clobber             don't clobber existing files.

  -c,  --continue               restart getting an existing file.

       --dot-style=STYLE        set retrieval display style.

  -N,  --timestamping           don't retrieve files if older than local.

  -S,  --server-response        print server response.

       --spider                 don't download anything.

  -T,  --timeout=SECONDS        set the read timeout to SECONDS.

  -w,  --wait=SECONDS           wait SECONDS between retrievals.

  -Y,  --proxy=on/off           turn proxy on or off.

  -Q,  --quota=NUMBER           set retrieval quota to NUMBER.



Directories:

  -nd  --no-directories            don't create directories.

  -x,  --force-directories         force creation of directories.

  -nH, --no-host-directories       don't create host directories.

  -P,  --directory-prefix=PREFIX   save files to PREFIX/...

       --cut-dirs=NUMBER           ignore NUMBER remote directory components.



HTTP options:

       --http-user=USER      set http user to USER.

       --http-passwd=PASS    set http password to PASS.

  -C,  --cache=on/off        (dis)allow server-cached data (normally allowed).

       --ignore-length       ignore `Content-Length' header field.

       --header=STRING       insert STRING among the headers.

       --proxy-user=USER     set USER as proxy username.

       --proxy-passwd=PASS   set PASS as proxy password.

  -s,  --save-headers        save the HTTP headers to file.

  -U,  --user-agent=AGENT    identify as AGENT instead of Wget/VERSION.



FTP options:

       --retr-symlinks   retrieve FTP symbolic links.

  -g,  --glob=on/off     turn file name globbing on or off.

       --passive-ftp     use the "passive" transfer mode.



Recursive retrieval:

  -r,  --recursive             recursive web-suck -- use with care!.

  -l,  --level=NUMBER          maximum recursion depth (0 to unlimit).

       --delete-after          delete downloaded files.

  -k,  --convert-links         convert non-relative links to relative.

  -m,  --mirror                turn on options suitable for mirroring.

  -nr, --dont-remove-listing   don't remove `.listing' files.



Recursive accept/reject:

  -A,  --accept=LIST                list of accepted extensions.

  -R,  --reject=LIST                list of rejected extensions.

  -D,  --domains=LIST               list of accepted domains.

       --exclude-domains=LIST       comma-separated list of rejected domains.

  -L,  --relative                   follow relative links only.

       --follow-ftp                 follow FTP links from HTML documents.

  -H,  --span-hosts                 go to foreign hosts when recursive.

  -I,  --include-directories=LIST   list of allowed directories.

  -X,  --exclude-directories=LIST   list of excluded directories.

  -nh, --no-host-lookup             don't DNS-lookup hosts.

  -np, --no-parent                  don't ascend to the parent directory.



Mail bug reports and suggestions to <bug-wget@gnu.org>.

wget2.HLP: No such file or directory
原文地址:https://www.cnblogs.com/alex-bn-lee/p/5072938.html