How Many Times Does wget Retry a Failed Connection?
This article provides a quick overview of the default retry behavior
of the wget command-line utility when a network connection
fails. It covers the specific default retry limit, explains how
wget handles different types of network errors, and
demonstrates how you can customize this behavior using command-line
flags to suit your specific downloading needs.
The Default Retry Limit
When you initiate a download using wget and the
connection encounters a failure, the utility is programmed to
automatically attempt to re-establish the connection and resume the
download. By default, wget will attempt to retry the
connection 20 times before it finally gives up and
reports a failure.
This high default number ensures that transient network hiccups, temporary server overloads, or brief connectivity drops do not completely ruin a long-running or automated download script.
How wget Handles Retries
wget distinguishes between different types of errors
before deciding whether to use one of its 20 default retries:
- Transient Errors: For issues like connection
timeouts, refused connections, or specific HTTP server errors (like 503
Service Unavailable),
wgetwill log the error, wait a few seconds, and then attempt a retry. - Fatal Errors: For errors that are clearly
unrecoverable—such as a “404 Not Found” or “403 Forbidden” response from
the server—
wgetwill recognize that retrying is pointless and will stop immediately without using up its retry quota.
How to Change the Default Number of Retries
While 20 retries is the standard setting, you can easily modify this
behavior using the -t or --tries option in
your terminal command.
- Set a Specific Number of Retries: If you only want
wgetto try 5 times before failing, you can specify that number directly:wget -t 5 https://example.com/file.zip - Infinite Retries: If you are on an unstable network
and absolutely must download a file no matter how many disconnects
occur, you can set the retries to infinite using
0orinf:wget -t 0 https://example.com/file.zip