How do I mirror a directory with wget without creating parent directories?

Tom Boutell picture Tom Boutell · Feb 18, 2011 · Viewed 72.2k times · Source

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.

Answer

vs_inf picture vs_inf · Feb 18, 2011

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.