我有一个web目录,我存储一些配置文件。我想使用wget将这些文件拉下来并保持它们当前的结构。例如,远程目录看起来像:

http://mysite.com/configs/.vim/

.vim包含多个文件和目录。我想用wget在客户端复制它。似乎无法找到正确的wget标志组合来完成这项工作。什么好主意吗?


当前回答

下面是完整的wget命令,用于从服务器目录下载文件(忽略robots.txt):

wget -e robots=off --cut-dirs=3 --user-agent=Mozilla/5.0 --reject="index.html*" --no-parent --recursive --relative --level=1 --no-directories http://www.example.com/archive/example/5.3.0/

其他回答

使用下面的命令,递归获取用户名和密码的目录:

wget -r --user=(put username here) --password='(put password here)' --no-parent http://example.com/
wget -r http://mysite.com/configs/.vim/

对我有用。

也许你有一个。wgetrc干扰它?

Wget 1.18可能工作得更好,例如,我被1.12版本的bug咬了,其中…

wget --recursive (...)

...只检索index.html而不是所有文件。

解决方法是注意到一些301重定向,并尝试新的位置-给定新的URL, wget得到目录中的所有文件。

首先,感谢所有发帖的人。这是我递归下载一个网站的“终极”wget脚本:

wget --recursive ${comment# self-explanatory} \
  --no-parent ${comment# will not crawl links in folders above the base of the URL} \
  --convert-links ${comment# convert links with the domain name to relative and uncrawled to absolute} \
  --random-wait --wait 3 --no-http-keep-alive ${comment# do not get banned} \
  --no-host-directories ${comment# do not create folders with the domain name} \
  --execute robots=off --user-agent=Mozilla/5.0 ${comment# I AM A HUMAN!!!} \
  --level=inf  --accept '*' ${comment# do not limit to 5 levels or common file formats} \
  --reject="index.html*" ${comment# use this option if you need an exact mirror} \
  --cut-dirs=0 ${comment# replace 0 with the number of folders in the path, 0 for the whole domain} \
$URL

之后,剥离查询参数从url像main.css?Crc =12324567并且运行一个本地服务器(例如通过python3 -m http。在你刚刚获得的目录下的server)来运行JS可能是必要的。请注意,——convert-links选项仅在完成完整爬行之后才生效。

此外,如果你正在尝试wget一个网站,可能很快就会宕机,你应该与ArchiveTeam联系,让他们把你的网站添加到他们的ArchiveBot队列中。

你只要加一个-r就可以了

wget -r http://stackoverflow.com/