Moving completed downloads to a different directory in aria2

Moving completed downloads to a different directory in aria2

By default, aria2 does not move completed downloads to a different directory than the one where downloads started. However, this behavior can be customized through the aria2 event hooks.

I used the on-download-complete event. A bash script can be specified in /home/she/.aria2/aria2.conf for this event as on line 15:

  1. dir=/home/she/aria2/download
  2. input-file=/home/she/.aria2/session
  3. log=/home/she/.aria2/log
  4. dht-listen-port=36801
  5. listen-port=36801
  6. max-overall-upload-limit=512K
  7. max-upload-limit=0
  8. seed-ratio=1.0
  9. seed-time=60
  10. enable-rpc=true
  11. rpc-listen-all=false
  12. rpc-listen-port=6800
  13. rpc-secret=1234567890
  14. log-level=notice
  15. on-download-complete=/home/she/.aria2/mvcompleted.sh
  16. max-overall-download-limit=0
  17. max-download-limit=0
  18. save-session=/home/she/.aria2/session

The bash script /home/she/.aria2/mvcompleted.sh reads:

  1. #!/bin/sh
  2.  
  3. # $1 is gid.
  4. # $2 is the number of files.
  5. # $3 is the path of the first file.
  6.  
  7. DOWNLOAD=/home/she/aria2/download # no trailing slash!
  8. COMPLETE=/home/she/aria2/complete # no trailing slash!
  9. LOG=/home/she/.aria2/mvcompleted.log
  10. SRC=$3
  11.  
  12. if [ "$2" == "0" ]; then
  13.   echo `date` "INFO  no file to move for" "$1". >> "$LOG"
  14.   exit 0
  15. fi
  16.  
  17. while true; do
  18.   DIR=`dirname "$SRC"`
  19.   if [ "$DIR" == "$DOWNLOAD" ]; then
  20.     echo `date` "INFO " "$3" moved as "$SRC". >> "$LOG"
  21.     mv --backup=t "$SRC" "$COMPLETE" >> "$LOG" 2>&1
  22.     exit $?
  23.   elif [ "$DIR" == "/" -o "$DIR" == "." ]; then
  24.     echo `date` ERROR "$3" not under "$DOWNLOAD". >> "$LOG"
  25.     exit 1
  26.   else
  27.     SRC=$DIR
  28.   fi
  29. done

Note that on-download-complete is triggered for all types of downloads when completed, while there is also a on-bt-download-complete, which is triggered after downloading is completed but before seeding is completed for BitTorrent downloads.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.