Go to the first, previous, next, last section, table of contents.


Following Links

When retrieving recursively, one does not wish to retrieve the loads of unnecessary data. Most of the time the users bear in mind exactly what they want to download, and want Wget to follow only specific links.

For example, if you wish to download the music archive from `fly.cc.fer.hr', you will not want to download all the home pages that happen to be referenced by an obscure part of the archive.

Wget possesses several mechanisms that allows you to fine-tune which links it will follow.

Relative Links

When only relative links are followed (option `-L'), recursive retrieving will never span hosts. No time-expensive DNS-lookups will be performed, and the process will be very fast, with the minimum strain of the network. This will suit your needs often, especially when mirroring the output of various x2html converters, since they generally output relative links.

Host Checking

The drawback of following the relative links solely is that humans often tend to mix them with absolute links to the very same host, and the very same page. In this mode (which is the default mode for following links) all URLs the that refer to the same host will be retrieved.

The problem with this option are the aliases of the hosts and domains. Thus there is no way for Wget to know that `regoc.srce.hr' and `www.srce.hr' are the same host, or that `fly.cc.fer.hr' is the same as `fly.cc.etf.hr'. Whenever an absolute link is encountered, the host is DNS-looked-up with gethostbyname to check whether we are maybe dealing with the same hosts. Although the results of gethostbyname are cached, it is still a great slowdown, e.g. when dealing with large indices of home pages on different hosts (because each of the hosts must be and DNS-resolved to see whether it just might an alias of the starting host).

To avoid the overhead you may use `-nh', which will turn off DNS-resolving and make Wget compare hosts literally. This will make things run much faster, but also much less reliable (e.g. `www.srce.hr' and `regoc.srce.hr' will be flagged as different hosts).

Note that modern HTTP servers allows one IP address to host several virtual servers, each having its own directory hieratchy. Such "servers" are distinguished by their hostnames (all of which point to the same IP address); for this to work, a client must send a Host header, which is what Wget does. However, in that case Wget must not try to divine a host's "real" address, nor try to use the same hostname for each access, i.e. `-nh' must be turned on.

In other words, the `-nh' option must be used to enabling the retrieval from virtual servers distinguished by their hostnames. As the number of such server setups grow, the behavior of `-nh' may become the default in the future.

Domain Acceptance

With the `-D' option you may specify the domains that will be followed. The hosts the domain of which is not in this list will not be DNS-resolved. Thus you can specify `-Dmit.edu' just to make sure that nothing outside of MIT gets looked up. This is very important and useful. It also means that `-D' does not imply `-H' (span all hosts), which must be specified explicitly. Feel free to use this options since it will speed things up, with almost all the reliability of checking for all hosts. Thus you could invoke

wget -r -D.hr http://fly.cc.fer.hr/

to make sure that only the hosts in `.hr' domain get DNS-looked-up for being equal to `fly.cc.fer.hr'. So `fly.cc.etf.hr' will be checked (only once!) and found equal, but `www.gnu.ai.mit.edu' will not even be checked.

Of course, domain acceptance can be used to limit the retrieval to particular domains with spanning of hosts in them, but then you must specify `-H' explicitly. E.g.:

wget -r -H -Dmit.edu,stanford.edu http://www.mit.edu/

will start with `http://www.mit.edu/', following links across MIT and Stanford.

If there are domains you want to exclude specifically, you can do it with `--exclude-domains', which accepts the same type of arguments of `-D', but will exclude all the listed domains. For example, if you want to download all the hosts from `foo.edu' domain, with the exception of `sunsite.foo.edu', you can do it like this:

wget -rH -Dfoo.edu --exclude-domains sunsite.foo.edu http://www.foo.edu/

All Hosts

When `-H' is specified without `-D', all hostsurn globbing on or off permanently. You may have to quote the URL to protect it from being expanded by your shell. Globbing makes Wget look for a directory listing, which is system-specific. This is why it currently works only with Unix FTP servers (and the ones emulating Unix ls output).

`--passive-ftp'
Use the passive FTP retrieval scheme, in which the client initiates the data connection. This is sometimes required for FTP to work behind firewalls.

Recursive Retrieval Options

`-r'
`--recursive'
Turn on recursive retrieving. See section Recursive Retrieval for more details.
`-l depth'
`--level=depth'
Specify recursion maximum depth level depth (See section Recursive Retrieval). The default maximum depth is 5.
`--delete-after'
This option tells Wget to delete every single file it downloads, after having done so. It is useful for pre-fetching popular pages through proxy, e.g.:
wget -r -nd --delete-after http://whatever.com/~popular/page/
The `-r' option is to retrieve recursively, and `-nd' not to create directories.
`-k'
`--convert-links'
Convert the non-relative links to relative ones locally. Only the references to the documents actually downloaded will be converted; the rest will be left unchanged. Note that only at the end of the download can Wget know which links have been downloaded. Because of that, much of the work done by `-k' will be performed at the end of the downloads.
`-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 -nr'.
`-nr'
`--dont-remove-listing'
Don't remove the temporary `.listing' files generated by FTP retrievals. Normally, these files contain the raw directory listings received from FTP servers. Not removing them can be useful to access the full remote file list when running a mirror, or for debugging purposes.

Recursive Accept/Reject Options

`-A acclist --accept acclist'
`-R rejlist --reject rejlist'
Specify comma-separated lists of file name suffixes or patterns to accept or reject (See section Types of Files for more details).
`-D domain-list'
`--domains=domain-list'
Set domains to be accepted and DNS looked-up, where domain-list is a comma-separated list. Note that it does not turn on `-H'. This option speeds things up, even if only one host is spanned (See section Domain Acceptance).
`--exclude-domains domain-list'
Exclude the domains given in a comma-separated domain-list from DNS-lookup (See section Domain Acceptance).
`-L'
`--relative'
Follow relative links only. Useful for retrieving a specific home page without any distractions, not even those from the same hosts (See section Relative Links).
`--follow-ftp'
Follow FTP links from HTML documents. Without this option, Wget will ignore all the FTP links.
`-H'
`--span-hosts'
Enable spanning across hosts when doing recursive retrieving (See section All Hosts).
`-I list'
`--include-directories=list'
Specify a comma-separated list of directories you wish to follow when downloading (See section Directory-Based Limits for more details.) Elements of list may contain wildcards.
`-X list'
`--exclude-directories=list'
Specify a comma-separated list of directories you wish to exclude from download (See section Directory-Based Limits for more details.) Elements of list may contain wildcards.
`-nh'
`--no-host-lookup'
Disable the time-consuming DNS lookup of almost all hosts (See section Host Checking).
`-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. See section Directory-Based Limits for more details.


Go to the first, previous, next, last section, table of contents. usr/doc/wget/html/wget_3.html100644 0 0 6365 6663627313 14531 0ustar rootroot GNU Wget Manual - Recursive Retrieval

Go to the first, previous, next, last section, table of contents.


Recursive Retrieval

GNU Wget is capable of traversing parts of the Web (or a single HTTP or FTP server), depth-first following links and directory structure. This is called recursive retrieving, or recursion.

With HTTP URLs, Wget retrieves and parses the HTML from the given URL, documents, retrieving the files the HTML document was referring to, through markups like href, or src. If the freshly downloaded file is also of type text/html, it will be parsed and followed further.

The maximum depth to which the retrieval may descend is specified with the `-l' option (the default maxi