Ubuntu – How to pause a running aria download

bashdownloadsscripts

When downloading big files it necessary to pause the download many times. A big file can be downloaded by using wget. First start download, then kill wget, then resume download by wget -c.
I want to pause downloads too many times depending on events such as power failure, Network unavailability, etc… and want to automate it using a script. So pressing Ctrl+C is't an option. I know a process can be paused by kill -STOP "$pid" The pausing should not close the connection to the website, either it should wait for resume command or the bandwidth throttled to very low use.

I found these commands using aria2c in aria2.sourceforge.net, but I can't use it successfully. This uses RPC method. Can I use it in a script?
aria2.pause(gid)

This method pauses the download denoted by gid. gid is of type string. The status of paused download becomes paused. If the download is active, the download is placed on the first position of waiting queue. As long as the status is paused, the download is not started. To change status to waiting, use aria2.unpause() method. This method returns GID of paused download.

aria2.unpause(gid)

This method changes the status of the download denoted by gid from paused to waiting. This makes the download eligible to restart. gid is of type string. This method returns GID of unpaused download.

Question

  1. How to pause (or throttle bandwidth) an already running download of aria
  2. Is there a better down loader than aria to use in script
  3. Wether RPC method can be used in script

Best Answer

For this to work your aria2 should support option pause. Search for --pause[=true|false] in man aria2c. It works in aria2_1.12.0-1_i386 [oneric] (and later).

First start RPC server: aria2c --enable-rpc=true (For older ver. aria2c --enable-xml-rpc=true)
Then use RPC using http://localhost:6800/jsonrpc
The following example adds http://example.org/file to aria2: In a python console type the following

JSON RPC

import urllib2, json
jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer',
    'method':'aria2.addUri',
    'params':[['http://example.org/file']]})
c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq)
c.read()
'{"id":"qwer","jsonrpc":"2.0","result":"2089b05ecca3d829"}'

The following example pause download whose GID is "3":

XML RPC

import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:6800/rpc')
s.aria2.pause('3')

If you get somethin like below your version of aria2 doesn't support it.

xmlrpclib.Fault: <Fault 1: 'No such method: aria2.pause'

In version that use aria2c --enable-xml-rpc=true, other options can be used such as adiing files, etc. (using XML RPC).