Download a file with aria2c using multiple connections
Issue
In Windows, we can use Internet Download Manager (IDM) and Neat Download Manager (NDM) to download files in multiple threads, and we can also use NDM to increase download speed in Mac. But in the Linux, the commands of wget
and curl
do not support multiple connections to download files.
Solution
The curl
command has an option of --range
, which we can retrieve a byte range (i.e. a partial docu-ment) from an HTTP/1.1, FTP or SFTP server or a local FILE. So we can write a small program to download a file with multiple connections, save them in multiple segment files, and finally merge them together. But here we can use aria2
.
aria2 is a utility for downloading files. The supported protocols are HTTP(S), FTP, SFTP, BitTorrent, and Metalink. aria2 can download a file from multiple sources/protocols and tries to utilize your maximum download bandwidth. It supports downloading a file from HTTP(S)/FTP/SFTP and BitTorrent at the same time, while the data downloaded from HTTP(S)/FTP/SFTP is uploaded to the BitTorrent swarm. Using Metalink's chunk checksums, aria2 automatically validates chunks of data while downloading a file like BitTorrent.
Using aria2
as follow:
aria2c -x 16 -s 16 [url]
# | |
# | |
# | |
# ---------> the number of connections here
-x, --max-connection-per-server=
The maximum number of connections to one server for each download. Default: 1
-s, --split=
Download a file using N connections. Default: 5