Is there a way to disable wget from getting files from parent directories to given depth?

I haven't tried it, but using -I and -X could give you what you want. My first tries would be along the line of

wget -m -I bar1/bar2 -X "*" http://www.foo.com/bar1/bar2/bar3/index.html

Explanation of options:

-m: 
   --mirror
       Turn on options suitable for mirroring.  This option turns on recursion and time-stamping, sets
       infinite recursion depth and keeps FTP directory listings.  It is currently equivalent to -r -N -l
       inf --no-remove-listing.
-I: list
   --include-directories=list
       Specify a comma-separated list of directories you wish to follow when downloading.  Elements of
       list may contain wildcards.
-X: list
   --exclude-directories=list
       Specify a comma-separated list of directories you wish to exclude from download.  Elements of list
       may contain wildcards.

You need to add a final / to the URL, else you'll not get what you want.

If you wanted to get all content at www.myhostname.com/somedirectory then the syntax should read like:

wget -r -nH http://www.myhostname.com/somedirectory/

Try it without the end / and see what happens. Then try it with the /.


I think the right answer here is the --no-parent option:

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

Tags:

Tree

Wget

Mirror