SkillPilotAI

aria2c (2/2)

Part 2 of aria2c covers the advanced options: how files are named, allocated and resumed, sessions and process control, DNS/interface/TLS, logging and event hooks, the input/config files, exit codes, and full remote control over JSON-RPC, XML-RPC and WebSocket notifications.

169.1 Why is it used?

  • Control disk behaviour: overwrite vs rename, file allocation, resume via the .aria2 control file.
  • Run long queues safely: -j limits, overall speed limits, --save-session to survive restarts, -D daemon mode.
  • Pick the resolver, interface and CA so downloads work in locked-down networks.
  • Script around aria2c with log levels, --on-download-complete/error hooks and exit codes.
  • Build web UIs or automation on the RPC API (addUri, tellStatus, pause, remove, notifications).

169.2 How it works

  • Lab: client 192.168.189.20 (aria2 1.37.0, GnuTLS, c-ares), server 192.168.189.10 (HTTP :80 with Range/206 and If-Modified-Since/304, HTTPS :443 lab CA, DNS stub :53 for files.lab, proxy stub :3128).
  • Progress of every piece is saved in file.aria2 next to the download (auto-saved every 60 s).
  • On restart aria2c reads the control file and sends a Range request for the rest.
  • With --enable-rpc it listens on 127.0.0.1:6800: /jsonrpc (JSON-RPC, also WebSocket) and /rpc (XML-RPC).
aria2c resume: control file + Range request
  1. 1.aria2c on 192.168.189.20 sends GET /big.bin to 192.168.189.10:80

  2. 2.200 OK, data starts arriving

  3. 3.Download stops halfway: progress kept in big.bin.aria2

  4. 4.Next run with -c reads the control file

  5. 5.Request goes with Range: bytes=212992-2097151

  6. 6.Server sends only the remaining part (206)

169.3 Files, resume and allocation

  • Same file twice: auto-file-renaming saves small.1.bin; --allow-overwrite=true replaces it.
  • --auto-file-renaming=false with an existing file and no control file: errorCode 13 (protects the file from truncation).
  • --file-allocation: none (only downloaded blocks), prealloc (writes full size first), trunc (size set, no blocks), falloc (reserves space in one call).
  • falloc on a 256k tmpfs: errorCode 9 "No space left on device".
  • -c resumes from the control file; --remove-control-file starts fresh; --conditional-get sends If-Modified-Since and skips on 304.
Terminal
U=http://192.168.189.10aria2c $U/small.binaria2c $U/small.binaria2c --auto-file-renaming=false $U/small.binfor a in none prealloc trunc falloc; do  rm -f big.bin big.bin.aria2  aria2c --file-allocation=$a --no-file-allocation-limit=0 --max-download-limit=100K --stop=2 -q $U/big.bin  ls -ls big.bindone
Output
$ aria2c $U/small.binf04e9a|OK  |   4.4MiB/s|/w/small.bind6fdaa|OK  |   0.9MiB/s|/w/small.1.bin$ aria2c --auto-file-renaming=false $U/small.binerrorCode=13 File /w/small.bin exists, but acontrol file(*.aria2) does not exist. Downloadwas canceled in order to prevent your filefrom being truncated to 0.# --file-allocation=none   128 -rw-r--r--  1 root  131072 big.bin# --file-allocation=prealloc  2048 -rw-r--r--  1 root 2097152 big.bin# --file-allocation=trunc   128 -rw-r--r--  1 root 2097152 big.bin
Terminal
aria2c --max-download-limit=200K --stop=2 -q $U/big.binls big.bin*aria2c -c $U/big.binaria2c --conditional-get --allow-overwrite=true $U/small.bin
Output
$ ls big.bin*big.binbig.bin.aria2$ aria2c -c $U/big.bin6b1be8|OK  |    48MiB/s|/w/big.binserver log:GET /big.bin Range=bytes=212992-2097151$ aria2c --conditional-get ... $U/small.binserver log: GET /small.bin  IMS=Mon, 09 Nov 2026 08:52:18 GMT[NOTICE] Download has already completed:  /w/small.bin
--file-allocationWhat happens on diskLab (2 MB file, stopped early)
noneOnly downloaded blocks exist128 KB blocks, size 131072
preallocFull size written up front (slow for big files)2048 KB blocks, size 2097152
truncSize set, no blocks (sparse)128 KB blocks, size 2097152
fallocSpace reserved in one fallocate call (fast)errorCode 9 on a tiny tmpfs

169.4 Sessions, limits and process

  • -j 2 runs two downloads at a time; --max-overall-download-limit=300K caps the total; --max-download-limit caps one.
  • --summary-interval=1 prints progress every second; --stop=3 halts after 3 seconds.
  • --save-session=s.txt stores unfinished downloads with their GID; aria2c -i s.txt finishes the queue.
  • -D daemon mode: ps masks the secret as ********; RPC listens on 127.0.0.1:6800 only; aria2.shutdown closes it.
  • Others: --conf-path, --no-conf, --save-session-interval, --force-save, --stop-with-process=PID.
Terminal
aria2c -i list.txt -j 2 --max-overall-download-limit=300K --summary-interval=1 --save-session=s.txt --stop=3cat s.txtaria2c -i s.txtaria2c -D --enable-rpc --rpc-secret=lab-only --dir=/w2/dnetstat -lnt | grep 6800
Output
[NOTICE] Downloading 3 item(s)[#37c8f1 320KiB/512KiB(62%) CN:1 DL:106KiB][#20f7bd 288KiB/512KiB(56%) CN:1 DL:148KiB]gid   |stat|avg speed  |path/URI37c8f1|INPR|   111KiB/s|/w2/a.bin20f7bd|INPR|   104KiB/s|/w2/b.bin$ cat s.txt gid=37c8f14cbd6f5d83 gid=20f7bd38d1283dac gid=0c7d94bfa0a2eb3e$ aria2c -i s.txt0c7d94|OK  |    23MiB/s|/w2/c.bin37c8f1|OK  |   3.5MiB/s|/w2/a.bin20f7bd|OK  |   4.2MiB/s|/w2/b.bin$ netstat -lnt | grep 6800tcp  0  0 127.0.0.1:6800   0.0.0.0:*   LISTENtcp  0  0 ::1:6800         :::*        LISTEN

169.5 Network, DNS and TLS

  • --async-dns-server=IP sends queries to that DNS server (lab stub resolved files.lab); a dead DNS IP gives errorCode 19.
  • --async-dns=false uses the system resolver (/etc/hosts worked for web.lab).
  • --interface=eth0 binds the socket; a missing eth9: errorCode 1.
  • Without the lab CA, GnuTLS fails: "issuer is not known"; --ca-certificate fixes it, also with --min-tls-version=TLSv1.3.
  • --check-certificate=false skips verification (lab only); --disable-ipv6 avoids slow AAAA lookups.
Terminal
S=192.168.189.10aria2c --async-dns-server=$S http://files.lab/small.binaria2c --async-dns-server=192.168.189.99 --timeout=3 --max-tries=1 http://files.lab/small.binaria2c --interface=eth9 http://$S/small.binaria2c https://$S/small.binaria2c --ca-certificate=/tmp/ca.crt --min-tls-version=TLSv1.3 https://$S/small.bin
Output
$ aria2c --async-dns-server=$S http://files.lab/...38eed7|OK  |   5.7MiB/s|/w3/small.binserver log:dns 192.168.189.20 query files.lab type 1$ aria2c --async-dns-server=192.168.189.99 ...errorCode=19 Name resolution for files.labfailed:Timeout while contacting DNS servers$ aria2c --interface=eth9 http://$S/small.binerrorCode=1 Failed to find given interfaceeth9, cause: not available$ aria2c https://$S/small.binerrorCode=1 SSL/TLS handshake failure:`not signed by known authorities or invalid'`issuer is not known'$ ... --min-tls-version=TLSv1.3 https://$S/small.bin572516|OK  |   3.2MiB/s|/w3/small.bin

169.6 Logging, console and event hooks

  • -l FILE --log-level=info: 47 lines for one small download; -q quiet console; --console-log-level=warn shows only warnings/errors.
  • --summary-interval=1 prints a summary every second; --show-console-readout=false hides the progress line.
  • Hooks get three arguments: GID, number of files, path.
  • -Z makes each URI a separate download; the missing file triggered the error hook with an empty path.
  • Other hooks: --on-download-start, --on-download-pause, --on-download-stop, --on-bt-download-complete.
Terminal
aria2c --console-log-level=warn $U/missing.binaria2c -q -Z --on-download-complete=/w4/done.sh --on-download-error=/w4/fail.sh $U/small.bin $U/nope.bincat hooks.log
Output
$ aria2c --console-log-level=warn $U/missing.bin[ERROR] CUID#7 - Download aborted.errorCode=3 Resource not found$ cat hooks.log08:53:10 error gid=51b52797f8e4a864 files=1 path=08:53:10 complete gid=c14cb554dd28a651 files=1  path=/w4/small.bin

169.7 Input file, config file and environment

  • Input file: one download per line; TAB-separated URIs are mirrors of the same file.
  • Lines starting with a space are per-download options (dir=, out=, max-download-limit=).
  • Default config ~/.aria2/aria2.conf (NAME=VALUE); --conf-path loads another file, --no-conf ignores it; XDG_CONFIG_HOME is read too.
  • http_proxy / https_proxy / ftp_proxy / all_proxy / no_proxy are honoured; a made-up ARIA2_DIR is not.
Terminal
cat -t uri.txtaria2c -i uri.txtcat /root/.aria2/aria2.confhttp_proxy=http://$S:3128 aria2c --no-conf -d /w5/px http://files.lab/hello.txtcat /w5/px/hello.txt
Output
$ cat -t uri.txthttp://192.168.189.10/a.bin^Ihttp://192.168.189.10/a.bin  dir=/w5/iso  out=first.imghttp://192.168.189.10/b.bin  max-download-limit=200K  out=second.img$ aria2c -i uri.txtf0099a|OK  |    17MiB/s|/w5/iso/first.imga3161a|OK  |   164KiB/s|/w5/second.img$ cat /root/.aria2/aria2.confdir=/w5/fromconfsummary-interval=0enable-color=false$ cat /w5/px/hello.txtproxy stub saw: GET http://files.lab/hello.txt

169.8 Exit status codes

  • Scripts should check the exit code; the lab reproduced 0, 1, 2, 3, 7, 9, 13, 19, 22 and 28.
  • A refused connection on a closed port gave 1 here, not 6 (6 = network problem stays in the table).
Terminal
A="aria2c --no-conf -q"$A $U/small.bin; echo $?$A --timeout=2 --max-tries=1 $U/slow; echo $?$A $U/missing.bin; echo $?$A --bogus-opt $U/small.bin; echo $?$A $U/err500; echo $?
Output
$ $A $U/small.bin; echo $?0$ $A --timeout=2 --max-tries=1 $U/slow; echo $?2$ $A $U/missing.bin; echo $?3$ $A --bogus-opt $U/small.bin; echo $?aria2c: unrecognized option: bogus-optDid you mean:	--out28$ $A $U/err500; echo $?22
CodeMeaningLab trigger
0All OKsmall.bin
1Unknown errorMissing interface eth9, TLS issuer unknown, connection refused
2Timeout--timeout=2 on /slow
3Resource not found404 missing.bin
7Unfinished downloads (stopped)--stop=1
9Not enough disk spacefalloc on 256k tmpfs
13File exists (no control file)--auto-file-renaming=false
19Name resolution failedDead DNS server / unknown name
22HTTP response error500 from /err500
24 / 28 / 32HTTP auth failed / bad option / checksum failed28: --bogus-opt

169.9 RPC interface

  • Every JSON-RPC call is a POST to /jsonrpc; the first param is "token:SECRET" (system.listMethods needs no token; 36 methods).
  • aria2.addUri takes the token, a URI list and options (own gid, max-download-limit) and returns the GID.
  • tellStatus / tellActive show progress; pause / unpause (resumes with a Range from byte 49152); changeGlobalOption changes limits live; getGlobalStat totals; remove -> status removed, errorCode 31.
  • system.multicall runs several methods in one request; a wrong secret: code 1 "Unauthorized".
  • XML-RPC on /rpc works the same (wrong token: faultCode 1); GET /jsonrpc?method=..&params=base64 also works.
aria2c RPC: client, daemon :6800 and file server
  1. 1.curl / web UI sends POST /jsonrpc aria2.addUri with token:lab-only

  2. 2.aria2c on 127.0.0.1:6800 checks the secret (wrong token = Unauthorized)

  3. 3.aria2c returns the GID, e.g. 1690000000000001

  4. 4.aria2c downloads http://192.168.189.10/big.bin

  5. 5.Client polls tellStatus or gets WebSocket notifications

  6. 6.onDownloadComplete is pushed when the file is done

JSON
{"jsonrpc":"2.0","id":"1", "method":"aria2.addUri", "params":["token:lab-only",  ["http://192.168.189.10/big.bin"],  {"gid":"1690000000000001",   "max-download-limit":"40K"}]}
Output
{"id":"1","jsonrpc":"2.0", "result":"1690000000000001"}rpc aria2.tellStatus -> {"completedLength":"49152",  "downloadSpeed":"25180","status":"active",  "totalLength":"2097152"}rpc aria2.unpause -> server log:GET /big.bin Range=bytes=49152-2097151rpc aria2.getGlobalStat -> {"downloadSpeed":"24135","numActive":"1",  "numStopped":"0","numStoppedTotal":"0",  "numWaiting":"0","uploadSpeed":"0"}rpc aria2.remove, tellStatus -> {"errorCode":"31","status":"removed"}$ rpc aria2.getGlobalStat "token:wrong"{"id":"1","jsonrpc":"2.0","error": {"code":1,"message":"Unauthorized"}}
MethodPurpose
aria2.addUri / addTorrent / addMetalinkAdd a download (URIs / base64 file)
aria2.tellStatus / tellActive / tellWaiting / tellStoppedStatus and queue lists
aria2.pause / unpause / forcePause / pauseAllPause control
aria2.remove / forceRemove / purgeDownloadResultRemove downloads / results
aria2.changeOption / changeGlobalOption / getGlobalStatOptions live, global stats
aria2.saveSession / shutdown / forceShutdownDaemon control
system.multicall / listMethods / listNotificationsBatch calls, introspection

169.10 WebSocket notifications and console readout

  • Notifications only come over WebSocket ws://host:6800/jsonrpc: onDownloadStart, Pause, Stop, Complete, Error, onBtDownloadComplete.
  • After addUri over websocat: first the GID reply, then aria2c pushed onDownloadStart and onDownloadComplete itself.
  • Console readout [#e74218 160KiB/256KiB(62%) CN:1 DL:80KiB ETA:1s] = first 6 hex of GID, done/total, connections, speed, ETA (torrents add SD/UL).
Terminal
( echo '{"jsonrpc":"2.0","id":"ws1","method":"aria2.addUri","params":["token:lab-only",["http://192.168.189.10/quarter.bin"],{"max-download-limit":"200K"}]}'  sleep 4 ) | websocat -t ws://127.0.0.1:6800/jsonrpc | head -3
Output
{"id":"ws1","jsonrpc":"2.0", "result":"25ab4d5453a06eec"}{"jsonrpc":"2.0","method":"aria2.onDownloadStart", "params":[{"gid":"25ab4d5453a06eec"}]}{"jsonrpc":"2.0","method": "aria2.onDownloadComplete",

169.11 Common mistakes

  • Thinking --rpc-secret makes port 6800 safe on the internet: it travels in plain HTTP and anyone with it can trigger downloads; keep 127.0.0.1, use an SSH tunnel or --rpc-secure.
  • Deleting the .aria2 file and expecting resume: it holds the piece progress.
  • --auto-file-renaming=false on an existing file: exit 13; use --allow-overwrite=true or keep the rename.
  • Expecting aria2c to read invented env vars like ARIA2_DIR: use aria2.conf or options.
  • Using --check-certificate=false instead of --ca-certificate.

169.12 Interview tips

  • How aria2c resumes: the .aria2 control file stores piece progress; on restart it sends a Range request for the remaining bytes (206).
  • --save-session + -i restores the whole queue after a restart.
  • Remote control: --enable-rpc --rpc-secret, JSON-RPC on /jsonrpc, XML-RPC on /rpc, push notifications only via WebSocket.
  • Know key exit codes: 0 OK, 2 timeout, 3 not found, 9 disk full, 13 file exists, 19 DNS failed, 24 auth failed.