How Does aria2 Resume Interrupted Downloads?
This article explains the underlying mechanism aria2 uses to resume
interrupted HTTP and FTP downloads. It covers how the utility tracks
download progress through control files, leverages protocol-specific
headers like Range and REST, and ensures file
integrity during a session restart.
The Core Mechanism:
The Control File (.aria2)
The secret to aria2’s ability to pick up exactly where it left off
lies in its control file. When you start a download, aria2 creates a
companion file with the .aria2 extension alongside your
target file.
- Progress Tracking: This control file maps out the entire download space, tracking which specific chunks (or segments) of the file have been successfully downloaded and which are still missing.
- Multi-Connection State: Because aria2 often downloads a single file using multiple connections or sources simultaneously, the control file keeps tabs on the exact byte boundaries assigned to each active thread.
When a download is interrupted by a network drop or user
cancellation, the .aria2 file remains on your disk. When
you re-run the command, aria2 reads this file to reconstruct the
download state, preventing the need to start from scratch.
Protocol-Level Resuming
Once aria2 knows which parts of the file are missing, it uses standard network protocol features to request only the remaining data from the server.
HTTP/HTTPS Resuming
For HTTP downloads, aria2 utilizes the standard Byte Ranges specification (RFC 7233).
- Server Capability Check: aria2 checks if the server
responded with the
Accept-Ranges: bytesheader during the initial connection. - The Range Header: If supported, aria2 sends a
request with a
Rangeheader specifying the exact byte offsets it needs. For example,Range: bytes=5000-10000tells the server to skip the first 5,000 bytes and only transmit the requested chunk.
FTP Resuming
For FTP downloads, aria2 relies on the REST
(Restart) command.
- Setting the Offset: Before initiating the file
transfer via the
RETR(Retrieve) command, aria2 sendsREST <byte-offset>to the FTP server. - Data Stream: The server moves its file pointer to that specific position and streams the data from that point forward.
File Integrity and Validation
Resuming a download introduces the risk of data corruption if the remote file changed while the download was paused. To protect against this, aria2 employs validation checks.
- Conditional Headers: For HTTP, aria2 can use the
If-Rangeheader combined with anETag(Entity Tag) or aLast-Modifiedtimestamp. If the file on the server has changed since the download was interrupted, the server rejects the range request and sends the fresh, complete file instead. - Checksum Verification: If you provide a hash (like MD5 or SHA-256) in the initial aria2 command, the utility will validate the completed file against that hash. If corruption occurred during the interruption, it can re-download the damaged segments.