通过 wget 下载目录和子目录

imb*_*ago 3 linux ssh bash wget

我在网络上有一个带有文件夹视图的文件夹(http://example.com/folder1/folder2/

/folder2 有多个文件夹,其中包含 pdf 文件。我想通过 ssh 将 /folder2 的所有内容下载到我的服务器,包括使用 wget 的所有子文件夹和文件。我已经尝试了以下但我一直只得到一个 index.html 和 robots.txt 文件。

[root@myserver downloads]# wget -r --no-parent --reject "index.html*" http://www.example.com/folder1/folder2/
--2015-08-07 07:46:36--  http://www.example.com/folder1/folder2/
Resolving www.example.com... 192.168.1.1
Connecting to www.example.com|192.168.1.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `www.example.com/folder1/folder2/index.html'

    [         <=>                           ] 4,874,325    138K/s   in 37s     

2015-08-07 07:47:42 (128 KB/s) -     `www.example.com/folder1/folder2/index.html' saved [4874325]

Loading robots.txt; please ignore errors.
--2015-08-07 07:47:42--  http://www.example.com/robots.txt
Connecting to www.example.com|192.168.1.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26 [text/plain]
Saving to: `www.example.com/robots.txt'

100%[======================================>] 26          --.-K/s   in 0s      

2015-08-07 07:47:42 (1.42 MB/s) - `www.example.com/robots.txt' saved [26/26]

Removing www.example.com/folder1/folder2/index.html since it should be rejected.

FINISHED --2015-08-07 07:47:42--
Downloaded: 2 files, 4.6M in 37s (128 KB/s)
[root@myserver downloads]# 
Run Code Online (Sandbox Code Playgroud)

我尝试过类似失败结果的其他命令:

wget -m -p -E -k -K -np http://example.com/folder1/folder2/

wget -r http://example.com/folder1/folder2/ -nd -P /downloads -A PDF
Run Code Online (Sandbox Code Playgroud)

buf*_*ufh 8

我想通过 ssh 将 /folder2 的所有内容下载到我的服务器,包括使用 wget 的所有子文件夹和文件。

我想你想通过下载wgetSSH 不是这里的问题。

解决方案通过阿蒂利奥

wget --mirror --page-requisites --adjust-extension --no-parent --convert-links \
    --directory-prefix=folder2 http://example.com/folder1/folder2/
Run Code Online (Sandbox Code Playgroud)

编辑

上述方案非常适合镜像网站;对不起,我回答得太快了,它不是镜像 PDF 的最佳选择。

wget -m -nH --cut-dirs=1 -np -R 'index.*' http://example.com/folder1/folder2/
Run Code Online (Sandbox Code Playgroud)
  • -m, --mirror: 递归下载所有内容
  • -nH, --no-host-directories: 不要将数据放在以主机名命名的目录中
  • --cut-dirs=1: 创建本地层次结构时跳过第一个目录
  • -np, --no-parent: 不取父母!
  • -R, --reject 'index.*': 不保存名为“index.*”的文件

可能有用:-e robots=off告诉 wget 忽略您的robots.txt.

例子

$ wget -m -nH --cut-dirs=4 -np --reject 'index.*' \
 http://ftp.lip6.fr/pub/linux/distributions/slackware/slackware64-current/source/a/bin/
$ tree
.
??? slackware64-current/
    ??? source/
        ??? a/
            ??? bin/
                ??? banners.tar.gz
                ??? bin.SlackBuild
                ??? debianutils_2.7.dsc
                ??? debianutils_2.7.tar.gz
                ??? fbset-2.1.tar.gz
                ??? scripts/
                ?   ??? diskcopy.gz
                ?   ??? xx.gz
                ??? slack-desc
                ??? todos.tar.gz
Run Code Online (Sandbox Code Playgroud)

选择

这不是你问的,但我个人喜欢用lftp它:

lftp -c "open http://example.com/folder1/; mirror folder2"
Run Code Online (Sandbox Code Playgroud)