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

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

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


当前回答

如果——没有家长帮助,你可以使用——include选项。

目录结构:

http://<host>/downloads/good
http://<host>/downloads/bad

你想下载的是downloads/good而不是downloads/bad目录:

wget --include downloads/good --mirror --execute robots=off --no-host-directories --cut-dirs=1 --reject="index.html*" --continue http://<host>/downloads/good

其他回答

wget -r http://mysite.com/configs/.vim/

对我有用。

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

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

wget -r http://stackoverflow.com/

这个版本递归下载,不创建父目录。

wgetod() {
    NSLASH="$(echo "$1" | perl -pe 's|.*://[^/]+(.*?)/?$|\1|' | grep -o / | wc -l)"
    NCUT=$((NSLASH > 0 ? NSLASH-1 : 0))
    wget -r -nH --user-agent=Mozilla/5.0 --cut-dirs=$NCUT --no-parent --reject="index.html*" "$1"
}

用法:

添加到~/。Bashrc或粘贴到终端 wgetod“http://example.com/x/”

递归wget忽略机器人(用于网站)

wget -e robots=off -r -np --page-requisites --convert-links 'http://example.com/folder/'

-e robots=off使它忽略该域的robots.txt

-r使它递归

-np = no parent,所以它不会跟随链接到父文件夹

递归下载一个目录,该目录拒绝index.html*文件,下载时不包含主机名、父目录和整个目录结构:

wget -r -nH --cut-dirs=2 --no-parent --reject="index.html*" http://mysite.com/dir1/dir2/data