Does Wget Have A Default Timeout?

Published August 17, 2024

Problem: Wget Timeout Settings

Wget is a command-line tool for downloading files from web servers. When using Wget, it's important to know its timeout behavior to avoid issues with downloads that may take longer than expected. This raises the question: Does Wget have a default timeout setting?

Wget Timeout Options and Configuration

Network Timeout Option

Wget lets you set network timeouts with the -T or --timeout option. This option sets one value in seconds for all network operations. It applies the same timeout for DNS lookups, connection attempts, and read operations.

To set a 60-second timeout for all network operations, use:

wget -T 60 http://example.com/file.zip

This command tells Wget to stop if any network task takes longer than 60 seconds.

Tip: Using Wget with a Configuration File

For repeated use of specific timeout settings, create a Wget configuration file. Add your preferred timeout settings to ~/.wgetrc:

timeout = 60
dns_timeout = 30
connect_timeout = 45
read_timeout = 120

This way, you don't need to specify timeout options on the command line each time you use Wget.

Specific Timeout Options

Wget also offers more control over timeouts with specific options:

DNS lookup timeout (--dns-timeout): This sets the maximum time for DNS resolution. Wget will stop if a DNS lookup takes longer than the set time. For example:

wget --dns-timeout=30 http://example.com/file.zip

Connect timeout (--connect-timeout): This sets how long Wget waits to connect to the server. Wget will stop if the connection isn't made within the set time. For instance:

wget --connect-timeout=45 http://example.com/file.zip

Read timeout (--read-timeout): This sets the maximum idle time during data transfer. Wget will stop the download if no data is received for the set time. For example:

wget --read-timeout=120 http://example.com/file.zip

These options give you more control over different parts of the download process, letting you adjust for network conditions or specific needs.