这并不是一个真正的问题 - 但当然欢迎其他答案!:)
有时我需要下载 Apache 目录列表中列出的文件,如下所示:
...在我的计算机上的给定目录中,我想为此使用命令行工具。
就目前而言wget
,实际上应该有一些开关 - 请注意,它们wget
往往要么下载单个项目,要么在本地重建服务器文件夹!
由于我刚刚花了大约半个小时弄清楚这些正确的开关是什么(通过 FTP 等方式在本地复制远程文件),因此我想在这里记录它们;所以上面的链接将被下载:
wget -nd -r -l 1 http://www.gnu-darwin.org/www001/src/ports/net/samba-libsmbclient/work/samba-3.0.28/source/libsmb/
Run Code Online (Sandbox Code Playgroud)
... 在哪里:
-nd
--no-directories
Do not create a hierarchy of directories when retrieving
recursively. With this option turned on, all files will get saved
to the current directory, without clobbering [...]
-r
--recursive
Turn on recursive retrieving.
-l depth
--level=depth
Specify recursion maximum depth level depth. The default maximum
depth is 5.
Run Code Online (Sandbox Code Playgroud)
很高兴听到上述命令的替代方案 - 也许使用不同的开关集wget
- 或者可能使用curl
或其他包......
一段时间后,感谢@jw013的指点以及与Apache服务器的目录列表同步,我终于找到了我的“终极”wget
命令。
假设您在名为 的目录中有一个文件和目录树myfiles_dir
,并让该目录可以通过 上列出的 Apache 目录访问http://localhost/shared/myfiles_dir
。然后,您可以使用以下命令在本地同步目录:
wget -r -N --no-parent --reject '*index.html*' -nH --cut-dirs=1 http://localhost/shared/myfiles_dir/
Run Code Online (Sandbox Code Playgroud)
... 在哪里:
-r, --recursive specify recursive download.
-N, --timestamping don't re-retrieve files unless newer than
local.
-np, --no-parent don't ascend to the parent directory.
-R, --reject=LIST comma-separated list of rejected extensions.
-nH, --no-host-directories don't create host directories.
--cut-dirs=NUMBER ignore NUMBER remote directory components.
Run Code Online (Sandbox Code Playgroud)
这会将内容下载到在调用myfiles_dir
目录wget
(工作目录)中创建的子目录中,没有任何残留index.html
文件。
请注意,http 链接/地址后面的尾部斜杠/
非常重要:如果它不存在 - 如http://localhost/shared/myfiles_dir
- 在从同一本地工作目录重复调用时wget
,目录列表的 HTML 将保存为多个副本,例如myfiles_dir.1
,myfiles_dir.2
等等,尽管有任何开关(尽管,不会根据要求保存内部任何子目录的 HTML 目录列表;而且,该命令第一次运行时,不会保存 的 HTML 目录列表myfiles_dir
)。
然而,使用尾部斜杠 - 如- 在从同一本地位置重复调用后,http://localhost/shared/myfiles_dir/
不会为任何目录(包括“root”)保存任何 HTML 目录列表。myfiles_dir
wget
归档时间: |
|
查看次数: |
6937 次 |
最近记录: |