Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Feb 13 '12 at 2:21

This question came from our site for professional and enthusiast programmers.

(Off topic, not really about programming or software development, voting to move to SuperUser.) – Bruno Feb 10 '12 at 23:13
@Bruno - Agreed – zellio Feb 10 '12 at 23:18
it is about software development - im writing an aspect FTP transfers within a piece of software – Dan Feb 11 '12 at 8:50

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

share|improve this answer

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

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


% find driver_C123_105.pkg


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

share|improve this answer

From man wget:

       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.
share|improve this answer
I can't get this to work. does it work for ftp too? – Dan Feb 10 '12 at 23:17
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 Feb 10 '12 at 23:21

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.

share|improve this answer

You must log in to answer this question.