wget - download all files but not preceding folders

11

3

I'm using wget to download all files from within a folder using the -r and -np options. However this also downloads the preceding folders, which I don't want.

For example:

wget -r -np ftp://user:pass@352.525.255.54/articles/artist/images/

this downloads all files from within "images" (which is good) but then also downloads the folders articles, artist and images (which is bad). What option fixes this?

Dan

Posted 2012-02-10T23:10:23.027

Reputation:

2(Off topic, not really about programming or software development, voting to move to SuperUser.) – Bruno – 2012-02-10T23:13:43.097

@Bruno - Agreed – zellio – 2012-02-10T23:18:06.010

it is about software development - im writing an aspect FTP transfers within a piece of software – None – 2012-02-11T08:50:40.210

Answers

9

I think what you are looking for is the --cut-dirs option. Used in conjunction with the -nH (no hostname) option, you can specify exactly which level of directory you want to appear in your local output. As an example, I have a .pkg download that I want to write to my local directory, and I don't want all of the parent tree to be included, just the subdirectories. In this case, my starting point to just get the .pkg name as the parent directory is 5 levels down:

wget -np -nH --cut-dirs 5 -r http://www.myhost.org/pub/downloads/My_Drivers/OS_10_5_x/Letter_Format/driver_C123_105.pkg

What you will see, then, is the name driver_C123_105.pkg in your current directory.

% ls -lt | head
drwxr-xr-x   12 rob  rob        408 Feb 22 12:54 driver_C123_105.pkg
-rw-------@   1 rob  rob          0 Feb 16 15:59 1kPSXcUj.pdf.part
-rw-------@   1 rob  rob        842 Feb  3 14:47 WcUuL69s.jnlp.part

[...etc...]

% find driver_C123_105.pkg
driver_C123_105.pkg
driver_C123_105.pkg/Contents
driver_C123_105.pkg/Contents/Archive.bom
driver_C123_105.pkg/Contents/Archive.pax.gz
driver_C123_105.pkg/Contents/index.html
driver_C123_105.pkg/Contents/index.html?C=D;O=A
driver_C123_105.pkg/Contents/index.html?C=D;O=D
driver_C123_105.pkg/Contents/index.html?C=M;O=A
driver_C123_105.pkg/Contents/index.html?C=M;O=D
driver_C123_105.pkg/Contents/index.html?C=N;O=A
driver_C123_105.pkg/Contents/index.html?C=N;O=D
driver_C123_105.pkg/Contents/index.html?C=S;O=A
driver_C123_105.pkg/Contents/index.html?C=S;O=D
driver_C123_105.pkg/Contents/Info.plist
driver_C123_105.pkg/Contents/PkgInfo
driver_C123_105.pkg/Contents/Resources
driver_C123_105.pkg/Contents/Resources/background.jpg

[.....etc....]

You can direct this output to go elsewhere with the -P option.

Robert Casey

Posted 2012-02-10T23:10:23.027

Reputation: 281

-nH refers to --no-host-directories – Rodrirokr – 2019-05-03T20:39:48.343

This is exactly it! in my case, was downloading busybox binaries from their page. wget --no-parent --no-host-directories --cut-dirs 3 -r https://busybox.net/downloads/binaries/1.30.0-i686/to get everything inside the 1.30.0-i686 directory. – Rodrirokr – 2019-05-03T21:28:57.597

7

The --no-parent-Option is what you are looking for.

fnl

Posted 2012-02-10T23:10:23.027

Reputation: 179

4

The asker already knows about --no-parent — he used the short version -np in the example command. It's more likely that he's looking for the --cut-dirs option, as in Robert Casey's answer.

– waldyrious – 2017-10-04T13:53:45.610

1

You might looking for this:

wget -r -np -nd ftp://user:pass@352.525.255.54/articles/artist/images/

The -nd switch is a short for --no-directories.

Straw Bury

Posted 2012-02-10T23:10:23.027

Reputation: 11

Stack Overflow, still quicker than reading manuals... thanks for your answer, exactly what I need :) – nicolas – 2017-04-13T14:22:10.740

2Note that with the -nd option, the entire directory structure will be discarded — so even if there are subdirectories below the one you're downloading, they won't be created, and all files will get saved to the root download directory. – waldyrious – 2017-10-04T13:58:16.803

0

From man wget:

   -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.

Bruno

Posted 2012-02-10T23:10:23.027

Reputation: 598

I can't get this to work. does it work for ftp too? – None – 2012-02-10T23:17:21.473

Not sure why it would go up the hierarchy at all with FTP, since it doesn't make sense to follow links there. Try perhaps with --mirror, or with a different FTP client (lftp, ncftp, ...) – Bruno – 2012-02-10T23:21:37.120