In order to avoid the --, -K/s
situations you can use --read-timeout=seconds
. This will timeout the connection after the amount of seconds.
If you need to go beyond that you can use this setup
wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0
This will retry refused connections and similar fatal errors (--retry-connrefused
), it will wait 1 second before next retry (--waitretry
), it will wait a maximum of 20 seconds in case no data is received and then try again (--read-timeout
), it will wait max 15 seconds before the initial connection times out (--timeout
) and finally it will retry an infinite number of times (-t 0
).
You might also want to put this in a while
loop in order to avoid local network failure and similar. In this case you also need to add --continue
in order to continue the download where you left off. The following works well in Bash
while [ 1 ]; do
wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0 --continue
if [ $? = 0 ]; then break; fi; # check return value, break if successful (0)
sleep 1s;
done;
As a bonus tip you can also use --no-dns-cache
in case the host balances your request between multiple servers by DNS.
Disclaimer: I do not recommend using this since it will spam the host in case the connection is unstable and it's kind of unwise to leave it unmonitored. However this is what you want in case you really need to download something and your connection doesn't work adequately.
2by default
--read-timeout=900
. You could just wait 15 minutes and wget will restart downloading. – Boris – 2017-09-10T09:23:32.760Thanks for this "retry" help, but for me it still doesn't work 100%, because wget ends with: Unable to establish SSL connection. It doesn't retries on that error. For reproducing try to wget https://pkg.jenkins.io/debian/jenkins.io.key
– Juraj Michalak – 2019-10-31T08:50:06.063There is also a
--retry-on-http-error=code
option. In my case the server returned errors 500 every now and then, so I needed to add the--retry-on-http-error=500
to make it work. – juanra – 2020-01-24T16:32:01.610