SkillPilotAI

aria2c (1/2)

aria2c is a lightweight command-line downloader that splits one file into pieces and fetches them over many connections and mirrors at once. It speaks HTTP(S), FTP, SFTP (if built in), Metalink and BitTorrent, resumes downloads, verifies checksums and can be driven remotely over JSON-RPC.

168.1 Why is it used?

  • Faster big downloads: several connections (-x) and pieces (-s) to one or many servers.
  • Reliability: -c resume, retries, timeouts and checksum verification (-V --checksum).
  • One file from many mirrors (Metalink) or from peers (BitTorrent) with a hash check at the end.
  • Automation: run as a daemon with --enable-rpc and control it with JSON-RPC.
  • Not built in anywhere: apt/dnf install aria2 (Linux), brew install aria2 (macOS), aria2c.exe / winget install aria2.aria2 (Windows).

168.2 How it works

  • Lab: client 192.168.188.20 (aria2 1.37.0, GnuTLS, no SFTP), n168-srv 192.168.188.10 (Range-capable HTTP server, lab-only tracker :6969, vsftpd, aria2c seeder :6881).
  • First a normal GET learns the size (Accept-Ranges: bytes); then each connection asks for its own Range.
  • Pieces are written into one file; a .aria2 control file next to it records progress for resume.
  • -k (min split size, default 20M) decides whether a file is worth splitting.
aria2c -x 4 -s 4: one file, four connections
  1. 1.Client sends GET /files/big.bin (no Range)

  2. 2.Server: 200 OK, Content-Length 4194304, Accept-Ranges: bytes

  3. 3.-s 4 splits the file into four 1 MiB pieces (-k 1M)

  4. 4.-x 4 opens four connections from four client ports

  5. 5.Each sends its own Range (1048576-2097151, 2097152-3145727, ...)

  6. 6.aria2c joins the pieces into one big.bin

168.3 Basic options

  • -d DIR folder, -o FILE name, -i FILE list of URLs (an indented out= line names that URL), -j N parallel downloads (default 5).
  • "stat OK" in Download Results = whole file arrived.
  • -l FILE writes a detailed log (77 lines even for a small file).
  • -c resumes using the partial file + .aria2 control file; the server log shows Range bytes=540672-.
  • -V checks integrity against a hash; --help=#http / #bittorrent or --help=proxy filters help.
Terminal
aria2c -d dl http://192.168.188.10/files/notes.txtcat urls.txtaria2c -q -d batch -i urls.txt -j 2timeout -s INT 2 aria2c --max-download-limit=500K -d part http://192.168.188.10/files/big.binls -l partaria2c -c -d part http://192.168.188.10/files/big.bin
Output
$ aria2c -d dl http://192.168.188.10/files/notes.txt11/09 08:39:30 [NOTICE] Downloading 1 item(s)11/09 08:39:31 [NOTICE] Download complete: dl/notes.txtDownload Results:gid   |stat|avg speed  |path/URI3e4c05|OK  |     163B/s|dl/notes.txt(OK):download completed.$ cat urls.txthttp://192.168.188.10/files/notes.txthttp://192.168.188.10/files/report.txt  out=report-2026.txt$ timeout -s INT 2 aria2c --max-download-limit=500K -d part ...(INPR):download in-progress.aria2 will resume download if the transfer is restarted.$ ls -l part-rw-r--r--  1 root  root  544088 Nov  9 08:39 big.bin-rw-r--r--  1 root  root      59 Nov  9 08:39 big.bin.aria2$ aria2c -c -d part http://192.168.188.10/files/big.binb43cf8|OK  |    19MiB/s|part/big.bin[srv]$ grep big.bin /srv/www.log | tail -208:39:59 192.168.188.20:36846 GET /files/big.bin range=-08:39:59 192.168.188.20:36850 GET /files/big.bin range=bytes=540672-4194303

168.4 HTTP/FTP/SFTP common options

  • Default is one connection (one GET in the server log).
  • -x 4 -s 4 -k 1M: four client ports, each asking a 1 MiB Range.
  • --max-download-limit=1M: the 4 MiB file took 4.61 s.
  • --connect-timeout=2 --max-tries=3 to an unused IP: three connect attempts, then "Download aborted".
  • --checksum=sha-256=HEX with -V: "Verification finished successfully"; one wrong character: "Checksum error".
  • This Alpine build has no SFTP: "sftp is not supported yet" (check aria2c -v Enabled Features).
Terminal
aria2c -x 4 -s 4 -k 1M -d multi http://192.168.188.10/files/big.bintime aria2c -q --max-download-limit=1M -d lim http://192.168.188.10/files/big.binaria2c --connect-timeout=2 --timeout=2 --max-tries=3 --retry-wait=2 -l retry.log http://192.168.188.99/files/big.binaria2c -V --checksum=sha-256=48fe0446...b91da8f1ab0 -d bad http://192.168.188.10/files/big.binaria2c sftp://192.168.188.10/files/notes.txt
Output
[srv]$ tail -4 /srv/www.log08:40:20 192.168.188.20:51010 GET /files/big.bin range=-08:40:20 192.168.188.20:51022 GET ... range=bytes=1048576-209715108:40:20 192.168.188.20:51014 GET ... range=bytes=2097152-314572708:40:20 192.168.188.20:51034 GET ... range=bytes=3145728-4194303$ time aria2c -q --max-download-limit=1M -d lim .../big.binreal	0m 4.61s$ grep -E 'Connecting to|attempted' retry.log08:40:38.979920 [INFO] CUID#7 - Connecting to 192.168.188.99:8008:40:40.984520 [INFO] CUID#7 - Connecting to 192.168.188.99:8008:40:42.062487 [INFO] CUID#7 - Connecting to 192.168.188.99:8008:40:44.066127 [INFO] CUID#7 - 3 times attempted, but no  success. Download aborted.$ aria2c -V --checksum=sha-256=48fe0446...1ab0 -d bad .../big.bin11/09 08:41:00 [ERROR] Checksum error detected. file=bad/big.bin3d24af|ERR |    38MiB/s|bad/big.bin(ERR):error occurred.$ aria2c sftp://192.168.188.10/files/notes.txtException: [AbstractCommand.cc:351] errorCode=1  -> errorCode=1 sftp is not supported yet.
OptionMeaningDefault
-x N / --max-connection-per-serverConnections to one server1
-s N / --splitPieces (connections) per file5
-k SIZE / --min-split-sizeDo not split ranges smaller than 2 x SIZE20M
-m N / --max-triesTries per URI5
-t S / --timeout, --connect-timeoutTimeouts60
--dry-runOnly check availability, no filefalse
--uri-selectorfeedback (fastest mirror), inorder, adaptivefeedback
--stream-piece-selector=inorderDownload from the start (play while downloading)default

168.5 HTTP and FTP specific options

  • No password on a protected file: errorCode=24 "Authorization failed"; --http-user / --http-passwd send Basic auth.
  • --header='N: v' adds headers, -U sets the User-Agent (server log shows ua=LabAgent/1.0).
  • Without a cookie /members gives 403 (errorCode=22); --load-cookies=cookies.txt (Netscape format) fixes it.
  • FTP: anonymous by default; --ftp-user / --ftp-passwd log in; passive (PASV) is default, --ftp-pasv=false sends PORT.
  • Other HTTP options: --ca-certificate, --certificate/--private-key, --check-certificate=false (lab only), --http-auth-challenge, --save-cookies, --referer.
Terminal
aria2c -d sec http://192.168.188.10/secure/plan.txtaria2c -q -d sec --http-user=labuser --http-passwd=LabPass168 http://192.168.188.10/secure/plan.txtaria2c -q -d club --load-cookies=cookies.txt http://192.168.188.10/members/club.txtaria2c -q -d ftp2 --ftp-user=labftp --ftp-passwd=FtpPass168 --ftp-pasv=false ftp://192.168.188.10/private.txt
Output
$ aria2c -d sec http://192.168.188.10/secure/plan.txt11/09 08:41:17 [ERROR] CUID#7 - Download aborted.Exception: [AbstractCommand.cc:351] errorCode=24  -> [HttpSkipResponseCommand.cc:215] errorCode=24     Authorization failed.$ cat sec/plan.txtonly for labuser[srv]$ grep secure /srv/www.log | tail -108:41:20 192.168.188.20:37742 GET /secure/plan.txt  ua=aria2/1.37.0 auth=Basic$ cat cookies.txt192.168.188.10  FALSE  /  FALSE  0  session  lab168cookie$ cat club/club.txtmembers only page[labftp] FTP command: ... "PORT 192,168,188,20,136,145"[labftp] FTP command: ... "RETR private.txt"

168.6 Metalink

  • A Metalink (.meta4) is XML with the file name, size, hash and a list of mirrors (with location and priority).
  • -M file.meta4 downloads from all mirrors at once; the hash must match before the file is complete.
  • Both lab mirrors are on one IP, so -x 2 was needed: HTTP sent 2 MiB and FTP sent 1 MiB.
  • --metalink-location=jp,us prefers mirrors by country; --metalink-preferred-protocol=https prefers a protocol.
Metalink: one file, two mirrors, one hash
  1. 1.aria2c -M lab.meta4 reads size 3145728, sha-256 and two URLs

  2. 2.Connects to the HTTP mirror 192.168.188.10:80

  3. 3.Connects to the FTP mirror 192.168.188.10:21 (data port 30004)

  4. 4.HTTP sends bytes 0-2097151, FTP sends 1048576 bytes

  5. 5.sha-256 check: "Verification finished successfully"

Terminal
cat lab.meta4aria2c -M lab.meta4 -d meta -s 2 -x 2 -k 1M -l meta.loggrep 'Connecting to' meta.log
Output
$ cat lab.meta4<metalink xmlns="urn:ietf:params:xml:ns:metalink">  <file name="mirror.bin">    <size>3145728</size>    <hash type="sha-256">a3cf586a...83344a9b</hash>    <url location="in" priority="1">http://192.168.188.10/files/mirror.bin</url>    <url location="de" priority="2">ftp://192.168.188.10/files/mirror.bin</url>  </file></metalink>$ aria2c -M lab.meta4 -d meta -s 2 -x 2 -k 1M -l meta.log11/09 08:42:06 [NOTICE] Verification finished successfully.  file=meta/mirror.binbf1489|OK  |    16MiB/s|meta/mirror.bin$ grep 'Connecting to' meta.log08:42:05.984883 CUID#7 - Connecting to 192.168.188.10:8008:42:05.985355 CUID#8 - Connecting to 192.168.188.10:2108:42:05.996053 CUID#8 - Connecting to 192.168.188.10:30004

168.7 BitTorrent (private lab torrent only)

  • Peers are found via trackers, DHT, LPD and peer exchange; in the lab DHT, DHT6, LPD and PEX were all off and only the lab tracker existed.
  • The seeder: aria2c -V --seed-ratio=0.0 (seed without limit) on port 6881.
  • -S file.torrent shows info hash, piece count and file index; --select-file=2 downloads only file 2.
  • --follow-torrent=false saves the .torrent instead of starting it; --seed-time=0 stops seeding right after.
BitTorrent with only a lab tracker and a lab seeder
  1. 1.Client announces to the lab tracker 192.168.188.10:6969 (event=started)

  2. 2.Tracker returns 1 peer: 192.168.188.10:6881 (the seeder)

  3. 3.Client connects to the seeder on 6881

  4. 4.Pieces flow seeder -> client (96 KiB)

  5. 5.--seed-time=0: seeding over, client announces event=stopped

DHT, LPD and PEX off, so no public network is touched

Terminal
aria2c -S t/lab-pack.torrentaria2c --enable-dht=false --enable-dht6=false --bt-enable-lpd=false --enable-peer-exchange=false --seed-time=0 -d bt -l bt.log t/lab-pack.torrentgrep -E 'Connecting to|Adding peer' bt.log
Output
$ aria2c -S t/lab-pack.torrentMode: multiAnnounce: http://192.168.188.10:6969/announceInfo Hash: 111091228c2bb35ee91be2aa6152159d4be6742dThe Number of Pieces: 4idx|path/length  1|./lab-pack/data.bin   |96KiB (98,304)  2|./lab-pack/readme.txt   |16B (16)$ aria2c --enable-dht=false ... --seed-time=0 -d bt -l bt.log t/lab-pack.torrent11/09 08:42:40 [NOTICE] IPv4 BitTorrent: listening on TCP port 688111/09 08:42:43 [NOTICE] Download complete: bt/lab-pack7c5d32|OK  |    53KiB/s|bt/lab-pack/data.bin (1more)$ grep -E 'Connecting to|Adding peer' bt.log08:42:40.455279 CUID#13 - Connecting to 192.168.188.10:696908:42:40.458653 Adding peer 192.168.188.10:688108:42:41.459102 CUID#14 - Connecting to 192.168.188.10:6881
  • More BT options: --bt-tracker (extra trackers), --bt-exclude-tracker, --bt-max-peers, --bt-require-crypto, --listen-port (6881-6999), -u / --max-upload-limit, --seed-ratio, --bt-remove-unselected-file (careful).

168.8 RPC options

  • --enable-rpc turns aria2c into a JSON-RPC/XML-RPC server, --rpc-listen-port (default 6800), -D runs it as a daemon.
  • By default it listens only on loopback (127.0.0.1 and ::1).
  • --rpc-secret=TOKEN: every call passes "token:..." as the first param; a wrong token gives Unauthorized.
  • --rpc-listen-all opens all interfaces: always pair it with --rpc-secret and --rpc-secure (TLS). --rpc-user/--rpc-passwd are deprecated.
Terminal
aria2c --enable-rpc --rpc-listen-port=6801 --rpc-secret=labRpc168 -Dnetstat -ltn | grep 6801curl -s http://127.0.0.1:6801/jsonrpc -d '{"jsonrpc":"2.0","id":"v1","method":"aria2.getVersion","params":["token:labRpc168"]}'
Output
$ netstat -ltn | grep 6801tcp   0   0 127.0.0.1:6801   0.0.0.0:*   LISTENtcp   0   0 ::1:6801         :::*        LISTEN$ curl -s http://127.0.0.1:6801/jsonrpc -d '{... "token:labRpc168"]}'{"id":"v1","jsonrpc":"2.0","result":{"enabledFeatures":  ["Async DNS","BitTorrent","Firefox3 Cookie","GZip","HTTPS",  "Message Digest","Metalink","XML-RPC"],"version":"1.37.0"}}$ curl -s http://127.0.0.1:6801/jsonrpc -d '{... "token:wrong"]}'{"id":"v2","jsonrpc":"2.0","error":{"code":1,  "message":"Unauthorized"}}

168.9 Common mistakes

  • Giving -x 16 for a 1 MB file and seeing one connection: the default -k 20M stops the split; add -k 1M -s N.
  • Assuming more connections = more speed: if your line is the bottleneck nothing changes, and servers may block you.
  • Using --check-certificate=false outside a lab.
  • Exposing RPC with --rpc-listen-all and no secret.
  • Running BitTorrent with DHT/PEX on when you only want a private tracker.

168.10 Interview tips

  • Reliable big download: -x 4 -s 4 -k 1M for parallelism, -c for resume, -V --checksum=sha-256=... for integrity.
  • Many mirrors: Metalink (-M file.meta4); automation: daemon with --enable-rpc --rpc-secret.
  • Splitting works only if the server supports Range (Accept-Ranges: bytes, 206 Partial Content).
  • The .aria2 control file is what makes resume possible: do not delete it mid-download.