How to Make Wget Retry Infinitely?
The wget command-line utility is a powerful tool for
downloading files from the web, but network instability can often
interrupt long-running transfers. By default, wget will
give up after a specified number of failed attempts. However, you can
configure it to retry an infinite number of times by using the
--tries=0 or -t 0 option. This article
explains how to implement this setting, combines it with other useful
flags for persistent downloads, and highlights important considerations
when running infinite retry loops.
Setting Wget Tries to Infinite
When automating scripts or downloading large files over unreliable
connections, you can force wget to keep trying forever
until the download succeeds. In wget, setting the retry
limit to 0 or inf tells the program never to
give up.
You can use either the short-form or long-form syntax:
- Short Option:
wget -t 0 [URL] - Long Option:
wget --tries=0 [URL] - Alternative Keyword:
wget --tries=inf [URL]
For example, to download a large ISO file with infinite retries, you would run:
wget -t 0 https://example.com/largefile.isoBest Practices for Persistent Downloads
While infinite retries ensure that wget won’t stop due
to connection drops, combining it with other specific flags creates a
much more robust and resilient download process.
1. Enable Resuming with
-c
If you use -t 0 without the resume flag,
wget might restart the download from the beginning (\(0\%\) bytes) every time the connection
drops. To prevent this and save bandwidth, pair it with the
--continue or -c option so it picks up right
where it left off.
wget -t 0 -c https://example.com/largefile.iso2. Handle Read Timeouts
with --timeout
Sometimes a connection doesn’t drop completely; instead, it “hangs”
and stalls indefinitely. By default, wget might wait a long
time before considering a stalled connection as failed. You can speed up
the retry trigger by setting a read timeout in seconds.
wget -t 0 -c --timeout=15 https://example.com/largefile.iso3. Adjust Wait Time Between Retries
To avoid overwhelming a server or getting your IP address temporarily
blocked for spamming requests, you can add a wait period between retry
attempts using the --wait flag.
wget -t 0 -c --wait=10 https://example.com/largefile.isoImportant Caveats
Before leaving an infinite wget script running in the
background, keep the following scenarios in mind:
- Permanent Errors (404 Not Found): Wget is smart
enough to recognize fatal HTTP errors. If the server responds with a
404 Not Foundor403 Forbidden,wgetwill stop immediately because retrying will not fix a missing file or permission issue. Infinite retries only apply to network timeouts, connection resets, and temporary server errors (like503 Service Unavailable). - Server Bans: Continually hammering a server that is
experiencing an outage can lead to your IP address being blacklisted by
automated firewalls or security plugins like Fail2ban. Always use a
reasonable
--waittime if you suspect the server is struggling.