Having a dedicated device for handling downloads becomes handy if you have a lot of downloading to do throughout the day. But maintaining a separate computer just for downloading is an overkill. Network Attached Storage (NAS) devices that are capable of downloading are quite expensive as well. Fortunately, we no longer have to look far thanks to the variety of inexpensive, single board computers that are rapidly gaining popularity today. The Raspberry Pi is in the forefront of this arena.
This post describes how to setup an inexpensive download box using a Raspberry Pi.
I had the following goals in mind when I started working on this project.
- Headless server setup which handles all the downloads
- Support for multiple protocols (BitTorrent, FTP and HTTP)
- Support for file sharing sites such as Mediafire, 4Shared, etc
- Ability to schedule and throttle bandwidth usage
- Accessible over the local network as well as the Internet
- Support for multiple platforms and devices (web, desktop and mobile clients)
Given below is a list of hardware I used together with their respective prices at the time of writing.
|Raspberry Pi 2 Kit||$49.95|
|Raspberry Pi Clear Acrylic Case||$12.99|
|MicroSD Card (8 GB, Class 10)||$6.99|
|External Hard Drive||N/A|
Note – Raspberry Pi is not capable of powering the external hard drive through the USB port. Therefore please make sure to get a hard drive with an external power supply, or use a flash drive with sufficient capacity for storage.
I was not able to find a single application for the Raspberry Pi which can handle both HTTP/FTP and BitTorrent downloads satisfactorily. Hence I decided to go ahead with 2 separate applications. I used PyLoad for HTTP/FTP downloads and Deluge for BitTorrent downloads.
- Follow the official guide here to get Raspbian installed on your SD card.
- Boot up the Raspberry Pi and go through the initial configuration (using raspi-config).
- Expand file system.
- Change the password for pi user.
- Set timezone using ‘Internationalization Options’.
- Enable SSH using ‘Advanced Options’.
- Configure Ethernet or WiFi (or both) for internet access (refer this link).
- Update and upgrade repositories:
sudo apt-get update
sudo apt-get upgrade
Mount USB Drive
- Attached the hard drive to Raspberry Pi and power it up.
- SSH into the Raspberry Pi using a tool such as Putty.
- Add NTFS support for Raspbian using the following command:
sudo apt-get install ntfs-3g
- Use the following command to see a list of attached hard drives and their partitions:
sudo fdisk -l
At a minimum you should be able to see two disks as shown in the screenshot below:
The first disk /dev/mmcb1k0 is the SD card inside the Raspberry Pi that has the Raspbian installation. The second disk, /dev/sda is the external hard drive that we are looking for. It has a single partition by the name of /sda1. Make a note of this.
- Create a folder to mount the hard drive:
sudo mkdir /media/USBHDD
- Mount the hard drive using the following command:
sudo mount -t auto /dev/sda1 /media/USBHDD
- We can create additional folders inside the hard drive to keep HTTP/FTP and BitTorrent downloads separate:
sudo mkdir /media/USBHDD/Downloads
sudo mkdir /media/USBHDD/Downloads/Files
sudo mkdir /media/USBHDD/Downloads/Torrents
- Install Samba so that we can access the downloads folder over the local network:
sudo apt-get install samba samba-common-bin
- Make a backup of Samba configuration file
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
- Edit Samba configuration file using the following command:
sudo nano /etc/samba/smb.conf
The first thing to change is the workgroup identifier, by default workgroup = WORKGROUP. If you’re using a different name for your home workgroup, go ahead and change that now, otherwise leave it as the default.
Next step is to turn on user authentication for the file share. Otherwise anyone who has access to the network will be able to access your downloads folder. Scroll down in the Samba configuration file until you come to the following section:
Remove the # symbol from ‘security = user’ line in order to enable username/password based authentication in Samba.
Next, we need to add a new section into the configuration file in order to define the file share and the users who are permitted to access it. You can add the following section to the bottom of the configuration file:
comment = Downloads Folder
path = /media/USBHDD/Downloads
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no
Note: What appears in square brackets in the first line is the name of the file share. Feel free to change it as you see fit.
Save changes to the Samba configuration file.
- Restart Samba daemon using the following command:
sudo /etc/init.d/samba restart
- Next we need to add a user who can access the downloads folder. We are going to create a new user account with username ‘downloads’ and password ‘1234’. You should change the username and password to your preference since this is the user who can access the downloads folder over the network.
sudo useradd downloads -m -G users
sudo passwd downloads
Enter the password twice in order to confirm.
- Add ‘downloads’ user as a valid Samba user using the following command:
sudo smbpasswd -a downloads
Enter the password for ‘downloads’ account when prompted.
- Use another machine to confirm whether the Samba share is visible and accessible over the local network. It should prompt and accept the credentials for ‘downloads’ user.
Once logged in, check whether you are able to see ‘Downloads’ folder, and ‘Files’ and ‘Torrents’ folders which are inside the downloads folder. Also make sure that you have permissions to write to downloads folder by creating a new file inside it.
- Create a new system user for running PyLoad:
sudo adduser –system pyload
- Add the following two lines to your /etc/apt/sources.list:
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi
- Update the package list and install dependencies that are needed by PyLoad:
sudo apt-get update
sudo apt-get -y install git liblept4 python python-crypto python-pycurl python-imaging tesseract-ocr zip unzip python-openssl libmozjs-24-bin
sudo apt-get -y build-dep rar unrar-nonfree
sudo apt-get source -b unrar-nonfree
sudo dpkg -i unrar_*_armhf.deb
sudo rm -rf unrar-*
ln -s js24 js
- Download the current version of PyLoad:
sudo git clone https://github.com/pyload/pyload.git
- Now you can run PyLoad and start configuring it:
sudo -u pyload python pyLoadCore.py
When pyLoadCore is run for the first time, it will walk you through a wizard which will configure the PyLoad installation for you. This wizard is self explanatory and has plenty of explanations on what is being configured, thus I will not go into details of this step here.
PyLoad runs on port 8000 or 7227 by default. This can be configured by using the above mentioned wizard.
Open up a browser and browse your PyLoad installation. Use the IP address of the Raspberry Pi and the port you configured during the installation wizard. If everything went fine, you should now be able to see the login page as shown below:
Log in, click on ‘Config’ button and go through the configuration options. Set download folder to ‘/media/USBHDD/Downloads/Files’ folder.
- You can create a systemd service file if you want to start PyLoad when the raspberry pi boots up. Create a new service file first:
sudo nano /etc/systemd/system/pyload.service
Add the following into the service file:
Activate the service using following command:
sudo systemctl enable pyload.service
A screenshot of PyLoad web interface is given below:
PyLoad also have mobile clients for Android, iOS and Windows Phone. A screenshot of the Android application is shown below:
PyLoad has a cross platform desktop client as well. However, it was not very mature at the time of writing.
- Install Deluge daemon and other required components:
sudo apt-get install deluged
sudo apt-get install deluge-console
- Run Deluge daemon and shut it down afterwards. This will create a configuration file which we will be editing in the next step:
sudo pkill deluged
- Make a backup of the configuration file and open the original for editing:
cp ~/.config/deluge/auth ~/.config/deluge/auth.old
- Add a line to the bottom of the configuration file which has the following format:
‘user’ and ‘password’ are the username and password we want for the Deluge installation. Please change the values as per your preference. Level can be set to 10 which represents full-access/administrative level for the daemon. I used ‘pi:raspberry:10’ for this.
Save changes to the configuration file.
- Start up Deluge daemon again and then the console:
If starting the console gives an error, type ‘exit’ and make sure you have started the daemon first.
- Enter the following commands once you are inside the console:
config -s allow_remote True
This enables remote connections to your Deluge daemon and double checks whether the config variable has been set.
- Kill the daemon and restart it one more time so that the config changes take effect:
sudo pkill deluged
At this point your Deluge daemon is ready for remote access. We need to install Deluge desktop client on your PC in order to connect to the daemon running on the Raspberry Pi.
- Download and install Deluge installer for your operating system from the downloads page.
- Open Deluge client and navigate to Preferences -> Interface. Within the interface sub menu, you’ll see a check box for ‘Classic Mode’. By default it is checked. Uncheck it.
- Click OK and then restart the Deluge desktop client.
Next time when Deluge starts, it will show the Connection Manager. Click the Add button and insert information about your Raspberry Pi and the Deluge daemon running inside it.
You will need to input the IP address of the Raspberry Pi on your network, as well as the username and password you set during the earlier configuration. Leave the port at the default 58846. Click Add.
Back in the Connection Manager, you will see the entry for the Raspberry Pi. If all goes well, the indicator light will turn green as shown below:
- Click on the Connect button. Deluge client will connect to the Daemon running on your Raspberry Pi and show the main interface as shown below:
Configure Deluge Download Location
We need to configure Deluge to download torrents into the external hard drive. We will also be creating a few additional folders to keep downloading and completed torrents separate. A watch folder will also be created and configured so that we can add torrents we need to download directly into the watch folder.
- SSH into the Raspberry Pi and run the following commands:
sudo mkdir /media/USBHDD/Downloads/Torrents/Downloading
sudo mkdir /media/USBHDD/Downloads/Torrents/Completed
sudo mkdir /media/USBHDD/Downloads/Torrents/Watch
sudo mkdir /media/USBHDD/Downloads/Torrents/Backup
- Open Deluge desktop client and navigate to Edit > Preferences > Downloads. Set download locations as shown below:
Install Deluge WebUI
Deluge WebUI allows you to use almost all the features of the desktop client at the convenience of a web interface. All you need to access it is a web browser, no additional client software installations are necessary. Follow the steps given below to install and configure Deluge WebUI.
- SSH into the Raspberry Pi and enter following commands:
sudo apt-get install python-mako
sudo apt-get install deluge-web
Above commands install Mako, a template gallery for Python that the WebUI needs, and the WebUI itself. It then starts the WebUI program.
The default port for the WebUI is 8112. If you wish to change it use the following commands:
sudo pkill deluge-web
This stops the WebUI and opens up the configuration file for it. Use nano to edit the line: “port”: 8112, and replace 8112 with a preferred port number.
After that, start WebUI again using the following command:
- Once you have the WebUI up and running, it’s time to connect into it using a web browser. Open up a browser on your regular desktop machine and point it at the IP address of your Pi (e.g. http://192.168.0.3:8112).
You’ll be greeted with a password prompt (the default password is ‘deluge’) and be immediately encouraged to change it after you enter it for the first time. After that, you’ll be able to interact with Deluge via the lightweight web interface:
Configure Deluge to Run on Startup
The last step in configuring Deluge is to set up Deluge daemon and WebUI to run automatically when the Raspberry Pi boots up.
- SSH into the Raspberry Pi and execute the following commands:
sudo wget -O /etc/default/deluge-daemon http://www.howtogeek.com/wp-content/uploads/gg/up/sshot5151a8c86fb85.txt
- Edit downloaded startup script:
sudo nano /etc/default/deluge-daemon
Change DELUGED_USER value to the username you used for Deluge daemon to run. After that, save changes and close nano editor.
- Make the script executable and update the startup file to include it:
sudo chmod 755 /etc/default/deluge-daemon
sudo update-rc.d deluge-daemon defaults
- Add the startup script to Raspbian:
sudo wget -O /etc/init.d/deluge-daemon http://www.howtogeek.com/wp-content/uploads/gg/up/sshot5151aa042ad11.txt
sudo chmod 755 /etc/init.d/deluge-daemon
sudo update-rc.d deluge-daemon defaults
- Restart Raspbian by using the following command:
After the Raspberry Pi restarts, attempt to connect to Deluge daemon by using either the desktop client or WebUI. If everything went smoothly, you should be able to connect and interact with the Deluge daemon.