Torrent

Post updated in August 2012
Torrent is without doubt one of the best protocols for sharing files.
For an archivist (a data hoarder), it is important to have a powerful, well-configured client that can handle thousands of torrents without using much memory.
My favorite clients for Linux are Deluge, Transmission and rTorrent. I have had trouble with
the first one, since it did not seem to cope with many files — about 600 at the time — and it often
froze. The second is simpler but very good, easy to configure and with interfaces for Gnome and KDE.
In this post I will cover the third one, rTorrent, which is the client I currently use and appears
to be the lightest, most powerful and most configurable.
rTorrent
rtorrent. The libtorrent install script installs versions of those packages automatically.
Installing through the package manager
Install rTorrent as explained on the wiki:
sudo pacman -S rtorrentThat is enough to get the latest stable version of rTorrent working. For many people that is enough, but I prefer to run the development version.
Another reason to compile rTorrent is to add patches, and I need it built with the
--with-xmlrpc-cflag.
Installing the dependencies
Create a folder for svn:
sudo mkdir /srv/svnMake your user the owner of that folder:
sudo chown -R julio.users /srv/svnRemove the programs that will be installed from svn:
sudo pacman -R xmlrpc-c rtorrentInstall CPPUNIT and libsigc++:
sudo pacman -S cppunit libsigc++Export the PKG_CONFIG_PATH variable:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig export PKG_CONFIG_PATHInstall xmlrpc-c:
cd /srv/svn svn co http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced xmlrpc-c cd xmlrpc-c ./configure make sudo make install
Installing from Git
AUR
When this post was first written, the rtorrent-git package did not yet exist on the AUR. In fact
rtorrent was kept in SVN at the time. But to our delight, a generous member of the community is
maintaining the package at this link: https://aur.archlinux.org/packages.php?ID=53151. Just
download it and run it — the PKGBUILD already comes with the flags I use.
By hand
Create a folder to keep programs downloaded with git:
[root@julio-acer ~]# mkdir /srv/git/ julio@julio-acer ~> cd /srv/gitClone libtorrent’s official repository
julio@julio-acer /srv/git> git clone https://github.com/rakshasa/libtorrentGo into the downloaded directory and compile libtorrent
julio@julio-acer /srv/git> cd libtorrent julio@julio-acer /srv/git/libtorrent> ./autogen.sh julio@julio-acer /srv/git/libtorrent> ./configure julio@julio-acer /srv/git/libtorrent> make julio@julio-acer /srv/git/libtorrent> make checkInstall libtorrent
julio@julio-acer /srv/git/libtorrent> sudo make installExport the PKG_CONFIG_PATH variable
julio@julio-acer ~> export PKG_CONFIG_PATH=/usr/local/lib/pkgconfigClone the rtorrent repository.
julio@julio-acer /srv/git> git clone https://github.com/rakshasa/rtorrentCompile rtorrent with the xmlrpc option (required by some interfaces)
julio@julio-acer /srv/git/rtorrent> ./autogen.sh julio@julio-acer /srv/git/rtorrent> ./configure --with-xmlrpc-c julio@julio-acer /srv/git/rtorrent> makeInstall rtorrent
julio@julio-acer /srv/git/rtorrent> sudo make install
Installing from SVN
UPDATE: rtorrent’s development moved to git and svn is only a mirror, so prefer the git installation explained above.
Install libtorrent:
cd /srv/svn svn co svn://rakshasa.no/libtorrent/trunk rtorrent cd rtorrent/libtorrent ./autogen.sh ./configure make sudo make install sudo ldconfigInstall rtorrent:
cd ../rtorrent ./autogen.sh ./configure - -with-xmlrpc-c (note the two dashes before with) make sudo make install
Configuring rTorrent
Configuration is done through the “~/.rtorrent.rc” file. Through it we can set rTorrent to:
- Use a specific port range
- Limit the download/upload speed
- Watch a folder and download every .torrent in it
- Run a script after a download finishes
- and much more…
On my laptop it works like this:
Everything is saved to an external drive, which is always connected
Inside the folder
/media/externo/Downloads/Torrents/rtorrent/watchthere are other folders- Ebooks » Holds
.torrentfiles for ebooks - Filmes » Holds
.torrentfiles for films - Musicas » Holds
.torrentfiles for albums - Seriados » Holds
.torrentfiles for TV series - Misc » Holds
.torrentfiles for every other category
- Ebooks » Holds
Those folders are constantly watched by rTorrent. When I put a .torrent file into one of them, it
starts the download automatically into the folder
/media/externo/Downloads/Torrents/leeching/{Ebooks,Filmes,Misc,Musicas,Seriados}/
Once the download finishes, the files are moved to the folder
/media/externo/Downloads/Torrents/seeding/{Ebooks,Filmes,Misc,Musicas,Seriados}/
Create the folders:
mkdir \ /media/externo/Downloads/Torrents/leeching/{Ebooks,Filmes,Misc,Musicas,Seriados,Programas} \ /media/externo/Downloads/Torrents/seeding/{Ebooks,Filmes,Misc,Musicas,Seriados,Programas} \ /media/externo/Downloads/Torrents/rtorrent/sessions \ /media/externo/Downloads/Torrents/rtorrent/watch/{Ebooks,Filmes,Misc,Musicas,Seriados,Programas}
I decided to keep the sessions and watch folders on the external drive, since that way I can plug it into another computer with rtorrent installed and carry on the transfers without trouble. To download something with the external drive disconnected, you have to use a modified .rtorrent.rc, since it will not find the sessions folder and will not even start.
My .rtorrent.rc can be found on GitHub. A good part of it was taken from here.
Magnet links
rTorrent 0.8.9
You will need to enable DHT.
Save the following script somewhere (I use ~/Scripts/magnet_torrent.sh here):
#!/bin/bash
cd /media/externo/Downloads/Torrents/rtorrent/watch/Misc
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"
julio@julio-acer ~> ~/Scripts/magnet_torrent.sh \
"magnet:?xt=urn:btih:1234567890&dn=Meu+Torrent&tr=udp%3A%2F%2Ftracker.com%3A80&tr=udp%3A%2F%2Ftracker2.com%3A80"
This command will create the file meta-1234567890.torrent in your folder.
RuTorrent
Using rTorrent with only the ncurses interface is a little awkward. A good solution is to
install a Web GUI.
Here I am using ruTorrent, similar to µtorrent’s interface,
which lets me manage the torrents through the web. To do that, Apache and PHP have to be configured
first.
Some of the steps were taken from the ArchLinux forum and from the ruTorrent wiki.
RuTorrent: installing through the package manager
Download ruTorrent, available on the AUR
Download mod_scgi
Download ruTorrent-plugins
Install geoip
sudo pacman -S php-geoipChange the folder’s permissions
sudo chmod 777 -R /srv/http/rutorrent/Edit the Apache configuration (/etc/httpd/conf/httpd.conf):
Listen 80 Add this at the end of the LoadModule section: LoadModule scgi_module modules/mod_scgi.so LoadModule php5_module modules/libphp5.soAfter # Various default settings, add a new section:
# php5 Include conf/extra/php5_module.conf Add this at the end of the file: SCGIMount /RPC2 127.0.0.1:5000:Protect the ruTorrent directory with a password
Create a password using htpasswd:
julio@julio-acer ~> htpasswd -c /home/julio/rtorrent/.htpasswd julio New password: Re-type new password: Adding password for user julioIn Apache:
<directory /srv/http/rutorrent/> AuthName "Log In" AuthType Basic AuthUserFile /home/julio/rtorrent/.htpasswd AuthGroupFile /dev/null require user julio </directory>
In /etc/php/php.ini:
Uncomment under html_errors:
- log_errors
- Default Value: On
Uncomment under Dynamic Extensions:
- extension=curl.so
- extension=pdo_sqlite.so
- extension=sockets.so
- extension=sqlite3.so
- extension=sqlite.so
- extension=xmlrpc.so
- extension=xsl.so
Make open_basedir look something like:
open_basedir = /usr/bin/:/usr/local/bin/:/srv/http/:/home/:/tmp/:/usr/share/pear/:/media/externo/Downloads/Torrents
In
/etc/php/conf.d/geoip.ini, uncomment:extension=geoip.soRestart the server
# /etc/rc.d/httpd restartTest the installation at http://localhost/rutorrent/
Installing from SVN
Just check out the repository
cd /srv/svn svn co http://rutorrent.googlecode.com/svn/trunk/rutorrent/ rutorrentConfigure it as usual
Plugins
ruTorrent has some very useful plugins. I
recommend the following ones:
Throttle
Lets you limit the download and/or upload speed per group of torrents.
julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/throttle
Ratio
Lets you stop uploading a torrent once a given ratio is reached.
julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/ratio
Track Labels
Adds a label with the tracker’s name to each torrent.
julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/tracklabel
Pyroscope
PyroScope contains several command-line tools and some
patches that make rTorrent considerably nicer to use. You do not need to install rTorrent as
explained above, since the PyroScope script installs a special version of rTorrent,
rTorrent-extended.
Pyrocore
The easiest way is through https://aur.archlinux.org/packages/rtorrent-pyro-git/.
Another easy way to install pyrocore would be with pip (sudo pip2 install pyrocore), but the
version there is very out of date.
The same goes for the version available on the AUR.
There is another version that looks more up to date, but I have not tried it.
On the project’s page there is a tutorial on installing everything from source. Here I will only try to explain the installation more clearly, but I recommend looking at the official site for fuller, more up-to-date information.
Install the dependencies
julio@acer ~> sudo pacman -S tmux python-virtualenvInstall rTorrent-extended
julio@julio-acer ~> mkdir ~/src; cd ~/src julio@julio-acer ~/src> svn co http://pyroscope.googlecode.com/svn/trunk/pyrocore/docs/rtorrent-extended julio@julio-acer ~/src> cd rtorrent-extended julio@julio-acer ~/src/rtorrent-extended> ./build.sh all julio@julio-acer ~/src/rtorrent-extended> ./build.sh extendInstall Pyroscope
julio@julio-acer ~> svn checkout http://pyroscope.googlecode.com/svn/trunk/ ~/lib/pyroscopeIf you are on Arch Linux, edit the path to python2 in the file
~/lib/pyroscope/update-to-head.sh:PYTHON=${1:-/usr/bin/python2}Run the script:
julio@julio-acer ~> ~/lib/pyroscope/update-to-head.shAdd
~/binto$PATH. Add the following line to.zshrcand.bashrc:export PATH="$HOME/bin:$PATH"Run the script to convert your
.rtorrent.rcto the new syntax:julio@julio-acer ~> ~/lib/pyroscope/pyrocore/docs/rtorrent-extended/migrate_rtorrent_rc.sh ~/.rtorrent.rcAdd this to
~/.rtorrent.rc:################################# ## PyroScope SETTINGS ################################# method.insert = pyro.extended, value|const, 1 method.insert = pyro.bin_dir, string|const, method.insert = pyro.rc_dialect, string|const|simple, "execute.capture=bash,-c,\"test $1 = 0.8.6 && echo -n 0.8.6 || echo -n 0.8.9\",dialect,$system.client_version=" method.insert = pyro.rtorrent_rc, string|const|private, "$cat=~/.pyroscope/rtorrent-,\"$pyro.rc_dialect=\",.rc.default" import = $pyro.rtorrent_rc= schedule = pyro_watchdog,30,300,"pyro.watchdog=~/.pyroscope," # Show traffic of the last hour network.history.depth.set = 112 schedule = network_history_sampling,1,32, network.history.sample= method.insert = network.history.auto_scale.toggle, simple|private, "branch=network.history.auto_scale=,\"network.history.auto_scale.set=0\",\"network.history.auto_scale.set=1\"" method.insert = network.history.auto_scale.ui_toggle, simple|private, "network.history.auto_scale.toggle= ;network.history.refresh=" branch=pyro.extended=,"schedule = bind_auto_scale,0,0,\"ui.bind_key=download_list,=,network.history.auto_scale.ui_toggle=\""Run the script to create a configuration:
julio@julio-acer ~> pyroadmin --create-configTest the installation
julio@julio-acer ~> which rtorrent /home/julio/bin/rtorrentjulio@julio-acer ~> rtorrentThe screen should be in color. Press
*to switch between collapsed view and expanded view.More tips can be found here
Note: If you open rTorrent inside GNU Screen and it complains about your terminal’s color count,
add the following line to ~/.screenrc: term screen-256color.
I have had trouble with the install script because of version compatibility problems. In that case you would have to downgrade several programs and run the script again.
Creating a .torrent with mktorrent
Besides downloading, sharing your files matters too. Staying true to the simplicity philosophy of Unix programs, rtorrent does not have a function for creating torrents.
For that task I use mktorrent.
Download mktorrent
julio@julio-acer ~ $ sudo pacman -S mktorrentMove every file to be shared into a folder of its own.
Run the command with the right parameters and options
mktorrent -v -p -a="ANNOUNCE" -c="COMMENT" -n="NAME" -o="OUTPUT.torrent"Where
-vVerbose-pmakes the torrent privateANNOUNCEis the URL the tracker gives youCOMMENTis some comment about the torrentNAMEis the package name, which ends up in the metainfo. Better to leave it out to avoid changing folder.OUTPUTis the name of the .torrent file
Example:
$ mktorrent -v -p -a "http://tracker.url/announce.php?passkey=123456xxxx&uid=xxxxx" -n "Artista - Ano - Album" -c "Original Release" -o album.torrent "Pasta_Ano - Disco" mktorrent 1.0 (c) 2007, 2009 Emil Renner Berthing Options: Announce URLs: 1 : http://tracker.url/announce.php?passkey=123456xxxx&uid=xxxxx Torrent name: Artista - Ano - Album Metafile: /media/externo/Musicas/album.torrent Piece length: 262144 Be verbose: yes Write date: yes Web Seed URL: none Comment: "Original Release" Adding cover.jpg Adding 01 - Track01.flac Adding 02 - Track02.flac Adding 03 - Track03.flac Adding 04 - Track04.flac Adding 05 - Track05.flac Adding Artist - Album.log Adding Album.cue 236381529 bytes in all. That's 902 pieces of 262144 bytes each. Hashed 902 of 902 pieces. Writing metainfo file… done.
If we try to use the same command to cross-seed — that is, to upload the same files to different trackers — rtorrent will return the error “Info hash already used by another torrent”. To solve that problem by making the hashes different, you can do the following:
Add or change some file when creating the second .torrent
Set a different piece size with the -l parameter. For example:
mktorrent -v -p -a "http://tracker.url/announce.php?passkey=123456xxxx&uid=xxxxx" -l 19 -o album_tracker2.torrent "Pasta_Ano - Disco"
which uses 512kb per piece.
ruTorrent also allows a multi-user setup, keeping each user’s files in specific folders
(rutorrent/share/users/USERNAME/settings/).
iPhone:
- http://code.google.com/p/torrentouch/
- http://code.google.com/p/rtorrent-for-iphone/
- http://kramerican.dk/index.php?page=rtorrent-for-iphone
Links

I’m a Brazilian computer engineer based in Germany, passionate about tech, science, photography, and languages.
I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.
I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, mentoring, and contributing with code and translations.
On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.
Browse my gallery for some of my photography.
Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.
Always happy to connect! 🙂