Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 688
Tom Boutell Avatar asked Feb 18 '11 15:02

Tom Boutell


People also ask

How do I download an entire directory using wget?

Typically, if you want to download directory & all subdirectories using wget command, you need to use -r option for recursive file transfer. Here is an example. You may also use –no-parent option to prevent wget from downloading parent directories.

What is wget recursive?

7 July, 2020. Wget can recursively download data or web pages. This is a key feature Wget has that cURL does not have. While cURL is a library with a command-line front end, Wget is a command-line tool.

What is the parent directory of your home directory?

All directories on a UNIX system are organized into a hierarchical structure that you can imagine as a family tree. The parent directory of the tree is known as the root directory and is written as a forward slash ( / ). The root contains several directories.


2 Answers

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.

like image 190
vs_inf Avatar answered Sep 19 '22 01:09

vs_inf


-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

like image 34
Marc B Avatar answered Sep 18 '22 01:09

Marc B