How to Resume a Partial Download with wget?
When downloading large files over a unstable internet connection,
interruptions can be incredibly frustrating. Fortunately, the
wget command-line utility provides a built-in feature that
allows you to pick up right where a failed or paused download left off,
saving you both time and bandwidth. This article provides a quick,
practical guide on how to use the resume function in wget,
covers the specific syntax required, and explains how to handle
potential troubleshooting scenarios.
The Core Command: Using the
-c Flag
The secret to resuming a partial download lies in the -c
(or --continue) option. When you use this flag,
wget checks the local directory for a partially downloaded
file matching the filename in the URL. If it finds one, it inspects the
file size and asks the server to send only the remaining portion of the
file.
To resume a download, simply open your terminal, navigate to the directory where the partial file is located, and run the following command:
wget -c https://example.com/largefile.zipImportant Note: For this to work seamlessly, you must run the command from the exact same directory where the incomplete file (e.g.,
largefile.zip) is stored.
How wget Behaves Under the Hood
When you initiate the resume command, wget executes a
specific sequence of checks to ensure data integrity:
- File Presence: It looks for a local file with the exact same name as the remote file.
- Size Comparison: If the local file is smaller than
the remote file,
wgetsends an HTTPRangerequest to the server, requesting the missing bytes. - Completion: If the local file is already the same
size (or larger) than the remote file,
wgetwill not download anything and will log a message stating that the file is already fully retrieved.
Handling Server-Side Limitations
While wget is highly efficient, its ability to resume a
download depends heavily on the hosting server.
- Supported Servers: Most modern web servers support byte-range requests (HTTP 1.1). When supported, the download resumes instantly.
- Unsupported Servers: If a server does not support
range requests,
wgetwill restart the download from 0%, overwriting or appending to the local file depending on the exact server response. If you notice the download starting over, the server likely lacks this capability.
Automating Resets on Dropped Connections
If you are dealing with a highly erratic connection and do not want to manually type the resume command every time the download drops, you can combine the continue flag with retry options:
wget -c --tries=infinite --retry-connrefused https://example.com/largefile.zipThis combination tells wget to automatically retry an
infinite number of times if the connection is refused or dropped, always
utilizing the -c flag to ensure it never restarts the
download from scratch.