如何使用 wget 镜像目录而不创建父目录?

发布于 2024-10-17 19:39:19 字数 632 浏览 8 评论 0原文

我想通过 FTP 镜像一个文件夹,如下所示:

wget --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper

但我不想创建如下目录结构:

ftp.site.com ->文件夹->子文件夹->甚至更深

我只是想要:

更深

及其以下的任何内容都是最终的结构。只要在服务器上为 evendeeper 的子目录创建子目录,evendeeper 的内容出现在当前目录中也是可以接受的。

我知道 -np 选项,根据文档,它只是阻止它跟踪到父页面的链接(对于我通过 FTP 镜像的二进制文件来说这不是问题)。我还知道 -nd 选项,但这根本无法创建任何目录结构,即使对于 evendeeper 的子目录也是如此。

我会考虑替代方案,只要它们是基于命令行的,可以作为 Ubuntu 软件包随时使用,并且可以像 wget 一样轻松自动化。

I want to mirror a folder via FTP, like this:

wget --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper

But I do not want to create a directory structure like this:

ftp.site.com -> folder -> subfolder -> evendeeper

I just want:

evendeeper

And anything below it to be the resulting structure. It would also be acceptable for the contents of evendeeper to wind up in the current directory as long as subdirectories are created for subdirectories of evendeeper on the server.

I am aware of the -np option, according to the documentation that just keeps it from following links to parent pages (a non-issue for the binary files I'm mirroring via FTP). I am also aware of the -nd option, but this prevents creating any directory structure at all, even for subdirectories of evendeeper.

I would consider alternatives as long as they are command-line-based, readily available as Ubuntu packages and easily automated like wget.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

星軌x 2024-10-24 19:39:19

对于如下路径: ftp.site.com/a/b/c/d

-nH 会将所有文件下载到目录 a/b/c/ d 在当前目录中,-nH --cut-dirs=3 会将所有文件下载到当前目录中的 d 目录中。

For a path like: ftp.site.com/a/b/c/d

-nH would download all files to the directory a/b/c/d in the current directory, and -nH --cut-dirs=3 would download all files to the directory d in the current directory.

孤城病女 2024-10-24 19:39:19

我有类似的要求,以下组合似乎是完美的选择:

在下面的示例中, http:// 中的所有文件url/dir1/dir2 (单独)被下载到本地目录 /dest/dir

wget  -nd -np -P /dest/dir --recursive http://url/dir1/dir2

感谢 @ffledgling 有关“-nd”的提示

对于上面的示例:

wget -nd -np --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper

来自手册的片段:

   -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 (if a name shows up more than once, the
       filenames will get extensions .n).


   -np
   --no-parent
       Do not ever ascend to the parent directory when retrieving recursively.  This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.

I had a similar requirement and the following combination seems to be the perfect choice:

In the below example, all the files in http://url/dir1/dir2 (alone) are downloaded to local directory /dest/dir

wget  -nd -np -P /dest/dir --recursive http://url/dir1/dir2

Thanks @ffledgling for the hint on "-nd"

For the above example:

wget -nd -np --mirror --user=x --password=x ftp://ftp.site.com/folder/subfolder/evendeeper

Snippets from manual:

   -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 (if a name shows up more than once, the
       filenames will get extensions .n).


   -np
   --no-parent
       Do not ever ascend to the parent directory when retrieving recursively.  This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.
过期以后 2024-10-24 19:39:19

-np (无父)选项可能会做你想要的,与 -L 1 结合在一起(我认为,在我之前没有安装 wget),这将递归限制为一级。

编辑。好的。啊...也许我应该等到我喝完咖啡...有一个 --cut 或类似的选项,它允许您从输出路径“剪切”指定数量的目录,因此,对于 /a/b/c/d,削减 2 将强制 wget 在本地计算机上创建 c/d

-np (no parent) option will probably do what you want, tied in with -L 1 (I think, don't have a wget install before me), which limits the recursion to one level.

EDIT. ok. gah... maybe I should wait until I've had coffee.. There is a --cut or similar option, which allows you to "cut" a specified number of directories from the output path, so for /a/b/c/d, a cut of 2 would force wget to create c/d on your local machine

恏ㄋ傷疤忘ㄋ疼 2024-10-24 19:39:19

而不是使用:

-nH --cut-dirs=1

使用:

-nH --cut-dirs=100

这将剪切更多目录并且不会创建任何文件夹。

注意:100 = 要跳过创建的文件夹数量。
您可以将 100 更改为任何数字。

Instead of using:

-nH --cut-dirs=1

use:

-nH --cut-dirs=100

This will cut more directories and no folders will be created.

Note: 100 = the number of folders to skip creating.
You can change 100 to any number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文