Tutorial #5: Efficient file sharing with remote BitTorrent + FTP Setup

Over the years, the word BitTorrent (or more popularly Torrent) has come to be associated with piracy in spite of it actually referring to a highly efficient peer to peer communication protocol. A typical complaint from a user is the speed of download which is highly dependent on the quality as well as quantity of peers available at a given point of time. Hence, it is usually much more efficient to have a BitTorrent based file download remotely, minimising the utilization of your own resources and then fetch the same using the standard FTP protocol. While there might be web services available that accomplish this, there is nothing like doing it yourself with full control. Note that the commands I have listed below are executed with root login. It is a better idea to operate as a normal user and escalate access using su or sudo whenever necessary. In your case, if you get an error when executing a command, then prefix ‘sudo’ to each.

Step 1: Get a cheap VPS
VPS refers to a Virtual Private Server. It is essentially a virtual machine running on a remote server while allowing you complete control over the machine. It serves as a great platform for learning without the fear of messing things up irreversibly. While costs and specifications vary, if your purpose is very specific and limited, it makes sense to purchase an annual subscription for a low end box which would cost a little more than $1/month. Of course, the specs will be downright modest with a single or dual core processor, 128 - 512 MB RAM, 100 GB or less of storage and around half a TB of bandwidth per month.

Step 2: Install an OS
When dealing with such a low end box, you have to purely operate a headless Linux server (through command line). Almost all VPS providers have a one-click OS install option. Make sure to choose a 32-bit minimal installation (my preference is for Debian) to maximize performance and minimize resource utilization.

Step 3: Log in to the server
Once installed, you will be able to login to your server using the SSH protocol. You only need the server IP address (available through Client Panel or your account initiation mail). On Linux, you would need nothing more than the terminal whereas on Windows, Putty is a really great client. If you would like to operate on the go, then JuiceSSH is an absolutely awesome SSH client on Android.

Step 4: Install a BitTorrent client
While there is quite an abundance of torrent clients available, what you really need is a client with a web access panel so that you can check the status and add torrents through any device. Transmission, rtorrent (with rutorrent), Deluge are the usual culprits here. However, I would recommend QBittorrent if you are not a particularly heavy user for it is quite light on the system, has a relatively meaty interface and is certainly reliable. Moreover, it has support for various proxy protocols that are lacking in the bellweather ones like Transmission and rtorrent. On Debian, you simply need to install it thorugh apt-get as follows. Before you do so, make sure you run the update and upgrade commands:
apt-get update && upgrade
apt-get install qbittorrent-nox
Step 5: Run the client 24x7
If you simply run the application on your terminal and then close the window, you will find that the client has stopped running. Hence, you need to ensure that it keeps running continuously. Doing so is possible by using the command:
nohup qbittorrent-nox &
disown -h %1
You can check the status using:
tail -f nohup.out
You can exit the status screen using Ctrl + C.

However, the better option is to use screen. If you are on a minimal install, you may need to install screen using:
apt-get install screen
You can then run a screen session by simply typing "screen" on the command prompt.

After accepting the initial disclaimer, you can run qbittorrent like you normally would.
You can now see the status of the client. You can detach yourself from this screen using:

Ctrl + A followed by D

The client will continue to run in to background and you may safely close the session.

To view all running screen sessions, you can use:
screen -ls
You can re-attach to a session using:
screen -r <session id>
You can quit a session using
screen -X -S <session id> quit
This covers all that you need to know to run the BitTorrent client in the background.

Step 6: Installing and accessing a FTP server

The BitTorrent client will get the file on your VPS and allow sharing of the same with others. But if you want to download the shared file efficiently, then it is best to install a FTP server so that you can download it using a FTP client or even from your browser. My personal preference is proftpd for I found it to be quite efficient and robust. The steps involved are as follows:

a. Install ProFTPd
apt-get install proftpd
b. Configure ProFTP for access control

For this, first open the config file
nano /etc/proftpd/proftpd.conf
Change the server name to your hostname by editing the following line:
ServerName "example.com"
Uncomment the ’DefaultRoot’ line so that access is limited to the user folder
# Use this to jail all users in their homes
DefaultRoot ~
You may now restart the FTP server
service proftpd restart
c. Accessing the FTP server

To access, either through the browser or a dedicated FTP client like FileZilla, you simply need to use the URL ‘ftp://example.com’ with the default port of 21.

Note that this instruction covers the insecure FTP protocol which transfers username and password using plain text. So it is not a great idea to use it on a website that is known to others. In that case, it a much better idea to use the SFTP protocol.

If you are sticking with insecure FTP, then it would be a good idea to use a separate login to do so. You can create a new user using the following command:
useradd username
Then, configure the password using:
passwd userpassword
Finally set the home directory using:
mkhomedir_helper username
As a final step, you should configure the torrent download directory through the GUI so that it is the same as this new user directory, in which case you will have direct access to the files each time you login using FTP.

With this you have a seamless 24x7 setup to file sharing and downloading at the maximum speed that your connection can afford. Going a step further, you can automate and schedule downloading of torrents on the remote machine and syncing them on your local machine but that may be a tutorial for some other day.