Remote Download Server in Linux using Aria2

Create your hustle free file download server with aria2 and RPi (Or any Linux distro)

Image for post
Image for post
Photo by Fancycrave on Unsplash

I’m using the steps which I followed in my Raspberry Pi. Don’t worry. They are applicable for other Linux distros too. Tested in Kali Linux and Ubuntu.

I’m using a Raspberry Pi 3 Model B as a small file download server. Which means when I need to download a torrent, I use my PI. The reason is, I don’t want to keep my laptop turned on all night long. So I use transmission as the torrent client. Transmission daemon runs as a systemd service in the background, and I use the web interface to interact.

Its very simple,

  • Turn on the PI which is in another place in the room.
  • Typing my PIs’ IP in a browser and access the transmission web interface using any of my devices in the local LAN.
  • Enter the username and password and done dusted for torrents.

Oh, I forgot! PI runs Kali Linux in headless mode.

Here comes the “but”. But my laptop still has to pay for its’ sins when I’m downloading a huge file over HTTP, HTTPS and etc, because I download them in off-peak time (0000h to 0800h). So had to come up with a solution. Opened the browser and summoned god Google. I just typed ‘downloader with a web interface for Linux headless’. For me, the first result was this link to ask ubuntu.

Aria2 is a file downloader just like wget. But much better for my need because aria2 being able to remotely controlled using JSON-RPC and XML-RPC interfaces. Bellow are some abstracts about aria2 and it’s a web interface.

Aria2 - “aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces.”

Web UI - “The aim for this project is to create the worlds best and hottest interface to interact with aria2. Very simple to use, just download and open index.html in any web browser.”

Alright. Enough intro about them. Let’s see how to get them working with an RPi.

Step 01 — Install aria 2 in your RPi

Image for post
Image for post
Install aria 2

Step 02 —Folders for the aria2 config file

You need to set up a different file to keep aria2 configurations. For me, I have a different user which I set-up for transmission. For now, let’s say that the user name is ‘user’. So ‘/user’ is the file I use for my downloads.
/user/torrents — for my torrents
/user/downloads — for downloads other than torrents (to keep separated from transmission)
/user/aria2/conf — new file for aria2 configurations

Step 03 — Configuration file

Then create a file named aria.conf in /user/aria2/conf

Image for post
Image for post
Add config file

And paste below configurations. Don’t panic yet! Just past them and come back.

Let me break down the configurations you are questioning right now.

01) dir=/user/downloads => It’s the location you need your downloaded file to save.
02) log=/user/aria2/aria2.log => aria2 log file location
03) input-file=/user/aria2/ses/aria2.session =>(Create ‘ses’ folder first) This is a must. This file will save all the URIs and details related to that URI in this file. Which means details of your download
04) save-session=/user/aria2/ses/aria2.session => “Save error/unfinished downloads to FILE(aria2.session) on exit. You can pass this output file to aria2c with — input-file option on restart. “
05) force-save=true => “Save download with — save-session option even if the download is completed or removed. This option also saves control file in that situations. “
06) IT’S-A MUST(for me) TO have steps 03, 04 and 05.
07) rpc-secret=*YOUR TOKEN* => in your terminal type ‘sudo openssl rand -base64 32’ and get your token and past it here. And keep hold of that token for Web UI configuration.

Don’t worry about the RPC-certificate part. You don’t need it because you’re using this set-up in your Local LAN. => Visit this to see all the aria2 configurations.

Step 04 — Testing configurations

Change daemon to false and console-log-level to info in the config file and save it. Now type,

Image for post
Image for post
Running aria2 with configurations

in the terminal and press enter and see the magic. You’ll see a lot of info messages and the terminal will hang up because daemon is set to false. Press Ctrl + C and close the aria2 process. You’ll see something like below,

Download Results:
gid |stat|avg speed |path/URI

Good luck and god speed. Aria2 works fine. Change back the configs (daemon to true and console-log-level to warn) and save the file.

Step 05 — Adding aria2 to as a systemd service

Image for post
Image for post
Adding a service file

Bellow is the gist you need to past

Save it and restart the RPi. Now type

Image for post
Image for post
Starting aria2 service

This starts your aria2 service. To see if it’s running,

Image for post
Image for post
Checking service status

You’ll see,

Image for post
Image for post
Running aria2 service

Step 06 — Installing apache2

For that, you can follow below link

Step 07 — Starting Apache2 and aria2 at startup

1 — Normally,

Image for post
Image for post
Adding aria2 service to start at boot
Image for post
Image for post
Adding apache2 service to start at boot

2 — And there is another method to do this in the kali RPi,

Search for ‘startup’ in Application Finer, Select ‘Session and Startup’, then ‘Application Autostart’ tab and finally ‘Add’

Image for post
Image for post

Do the same for Apache2.

Step 08 — Getting aira2 Web UI

Go to the folder which apache servers the web pages

Image for post
Image for post
Default folder

and then,

Image for post
Image for post
Cloning Web UI

And you can copy the ‘docs’ folder to /var/www/html and rename it to aria2. Access Web UI using a browser by typing https://your_server_ip/aria2

That’s it, guys. Now you can access your aria2 service through a Web-UI from any device in your LAN. But, there’s a problem. You need to enter your token which you generated in Step 03–07 into Settings -> Connection Settings -> Enter the secret token. Once per device! But if you don’t want to do that you can follow the below steps.

Step 09 — Building angular project with Secret Token

Hoping you have nodejs and npm installed, inside webui-aria2 folder in your terminal type, npm install. Then open the file /src/js/services/configurations.js

Uncomment — //token: ‘$YOUR_SECRET_TOKEN$’
and put your token generated from Step 03–07 and save the file.

Which is — token: ‘YOUR_TOKEN’

Then run the build script using npm run build and follow Step 08 and don’t forget to allow port 6800 for incoming traffic if ufw is enabled.

Yep! We did it. Hope you guys liked this article. Yeah, I know. It’s a long list of steps. But I tried my best as this is my first article. Hope this article has helped you if you’re reading this part. Cya!

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store