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:

For example, to download a large ISO file with infinite retries, you would run:

wget -t 0 https://example.com/largefile.iso

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

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

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

Important Caveats

Before leaving an infinite wget script running in the background, keep the following scenarios in mind: