Torrent

Post updated in August 2012

This article is quite dated. My current recommendation is to use Docker.

Undoubtedly, torrent is one of the best protocols for file sharing.

For a data hoarder, it is important to have a powerful and well-configured client to handle thousands of torrents without using too much memory.

My favorite clients for Linux are Deluge, Transmission, and rTorrent. I had issues with the first one as it seemed to struggle with many files, around 600 at the time, and often crashed. The second one is simpler but very good, easy to set up, and with interfaces for Gnome and KDE. In this post, I will focus on the third one, rTorrent, which is the client I currently use and seems to be the lightest, most powerful, and with more configuration options.

rTorrent

ATTENTION: If you want to use Pyroscope, skip the installation of xmlrpc, libtorrent, and rtorrent. The libtorrent installation script automatically installs versions of these packages.

Installation via package manager

  1. Install rTorrent as explained in the wiki:

    sudo pacman -S rtorrent
    

    This is enough to have the latest stable version of rTorrent working. For many people, this is sufficient, but I prefer to run the development version.

    Another reason to compile rTorrent is to add patches, and I need it to be a version compiled with the --with-xmlrpc-c flag.

Installing dependencies

  1. Create a folder for svn:

      sudo mkdir /srv/svn
    
  2. Set your user as the owner of this folder:

      sudo chown -R julio.users /srv/svn
    
  3. Remove the programs that will be installed via svn:

      sudo pacman -R xmlrpc-c rtorrent
    
  4. Install CPPUNIT and libsigc++:

      sudo pacman -S cppunit libsigc++
    
  5. Export the PKG_CONFIG_PATH variable:

      PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
      export PKG_CONFIG_PATH
    
  6. Install 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
    

Installation via Git

AUR

As of the first edition of this post, the rtorrent-git package did not exist in the AUR. In fact, rtorrent was maintained in SVN at the time. But to our delight, a generous community member is maintaining the package at this link: https://aur.archlinux.org/packages.php?ID=53151. Just download and run it, the PKGBUILD already comes with the flags I use.

Manually

  1. Create a folder to keep programs downloaded with git:

    [root@julio-acer ~]# mkdir /srv/git/
    julio@julio-acer ~> cd /srv/git
    
  2. Clone the official libtorrent repository

    julio@julio-acer /srv/git> git clone https://github.com/rakshasa/libtorrent
    
  3. Enter 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 check
    
  4. Install libtorrent

    julio@julio-acer /srv/git/libtorrent> sudo make install
    
  5. Export the PKG_CONFIG_PATH variable

    julio@julio-acer ~> export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    
  6. Clone the rtorrent repository.

    julio@julio-acer /srv/git> git clone https://github.com/rakshasa/rtorrent
    
  7. Compile 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> make
    
  8. Install rtorrent

    julio@julio-acer /srv/git/rtorrent> sudo make install
    

Installation via SVN

UPDATE: The development of rtorrent has been moved to git, and svn is just a mirror, so prefer installation via git, as explained above.

  1. Install libtorrent:

    cd /srv/svn
    svn co svn://rakshasa.no/libtorrent/trunk rtorrent
    cd rtorrent/libtorrent
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ldconfig
    
  2. Install rtorrent:

    cd ../rtorrent
    ./autogen.sh
    ./configure - -with-xmlrpc-c (perceba os dois traços antes de with)
    make
    sudo make install
    

rTorrent Configuration

The configuration is done through the file “~/.rtorrent.rc”. Through it, we can configure rTorrent to:

  • Use a specific range of ports
  • Limit download/upload speed
  • Watch a folder and download all .torrent files from it
  • Run a script after download completion
  • and much more…

On my notebook, the setup is as follows:

  • Everything is saved on an external hard drive, which is always connected

  • In the folder /media/externo/Downloads/Torrents/rtorrent/watch, there are other folders

    • Ebooks » Contains .torrent files for ebooks
    • Movies » Contains .torrent files for movies
    • Music » Contains .torrent files for albums
    • TV Shows » Contains .torrent files for TV series
    • Misc » Contains .torrent files for all other categories

These folders are constantly monitored by rTorrent. When I add a .torrent file to any of them, it automatically starts downloading to the folder /media/externo/Downloads/Torrents/leeching/{Ebooks,Movies,Misc,Music,TV Shows}/

After the download is complete, the files are moved to the folder /media/externo/Downloads/Torrents/seeding/{Ebooks,Movies,Misc,Music,TV Shows}/

  • 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 hard drive so that I can connect it to another computer with rtorrent installed and continue transfers without any issues. To download something with the external hard drive disconnected, a modified .rtorrent.rc file will be needed, as it won’t find the sessions folder or initialize.

My .rtorrent.rc can be found on GitHub. Much of it was taken from here.

Magnet URI

rTorrent 0.8.9

You will need to enable DHT.

Save the following script somewhere (using ~/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=My+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 only with the ncurses interface is a bit complicated. A good solution is to install a Web GUI.

Here I am using ruTorrent, similar to the interface of µtorrent, which allows me to manage torrents via the web. For this, it is necessary to configure Apache and PHP first.

Part of the steps were taken from the ArchLinux forum and the ruTorrent wiki.

RuTorrent: Installation via package manager

  1. Download ruTorrent available on AUR

  2. Download mod_scgi

  3. Download ruTorrent-plugins

  4. Install geoip

    sudo pacman -S php-geoip
    
  5. Change permissions of the folder

    sudo chmod 777 -R /srv/http/rutorrent/
    
  6. Edit Apache settings (/etc/httpd/conf/httpd.conf):

    Listen 80
    Adicione ao final da sessão LoadModule:
    LoadModule scgi_module modules/mod_scgi.so
    LoadModule php5_module modules/libphp5.so
    

    After # Various default settings add a new section:

    # php5
    Include conf/extra/php5_module.conf
    Adicione ao final do arquivo:
    SCGIMount /RPC2 127.0.0.1:5000:
    
  7. Protect the ruTorrent directory with a password

    1. 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 julio
      
    2. In Apache:

      <directory /srv/http/rutorrent/>
      AuthName "Log In"
      AuthType Basic
      AuthUserFile /home/julio/rtorrent/.htpasswd
      AuthGroupFile /dev/null
      require user julio
      </directory>
      
  8. In /etc/php/php.ini:

    1. Uncomment in html_errors:

      • log_errors
      • Default Value: On
    2. Uncomment in Dynamic Extensions:

      • extension=curl.so
      • extension=pdo_sqlite.so
      • extension=sockets.so
      • extension=sqlite3.so
      • extension=sqlite.so
      • extension=xmlrpc.so
      • extension=xsl.so
    3. Leave the open_basedir similar to:

      open_basedir = /usr/bin/:/usr/local/bin/:/srv/http/:/home/:/tmp/:/usr/share/pear/:/media/external/Downloads/Torrents
      
  9. In /etc/php/conf.d/geoip.ini, uncomment:

    extension=geoip.so
    
  10. Restart the server

    # /etc/rc.d/httpd restart
    
  11. Test the installation at http://localhost/rutorrent/

Installation via SVN

  1. Just checkout the repository

    cd /srv/svn
    svn co http://rutorrent.googlecode.com/svn/trunk/rutorrent/ rutorrent
    
  2. Configure as usual

Plugins

ruTorrent has some very useful plugins. I recommend the following plugins:

Throttle

Allows limiting the download and/or upload speed per torrent group.

julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/throttle

Ratio

Allows stopping uploading a torrent after reaching a certain ratio.

julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/ratio

Track Labels

Adds a label with the tracker name to each torrent.

julio@acer http/rutorrent/plugins> sudo svn co http://rutorrent.googlecode.com/svn/trunk/plugins/tracklabel

Pyroscope

PyroScope contains various command-line tools and some patches that greatly enhance the use of rTorrent. You do not need to install rTorrent as explained above, as the PyroScope script installs a special version of rTorrent, the 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 outdated.

The same goes for the version available on AUR.

There is another version that seems to be more up to date, but I haven’t tested it.

On the project page, there is a tutorial on how to install everything from the source code. Here I will only try to explain more clearly how to install, but I recommend checking the official website for more complete and updated information.

  1. Install dependencies

    julio@acer ~> sudo pacman -S tmux python-virtualenv
    
  2. Install 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 extend
    
  3. Install Pyroscope

    julio@julio-acer ~> svn checkout http://pyroscope.googlecode.com/svn/trunk/ ~/lib/pyroscope
    

    If 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.sh
    

    Add ~/bin to the $PATH. Add the following line to .zshrc and .bashrc:

    export PATH="$HOME/bin:$PATH"
    

    Run the script to convert your .rtorrent.rc to the new syntax:

    julio@julio-acer ~> ~/lib/pyroscope/pyrocore/docs/rtorrent-extended/migrate_rtorrent_rc.sh ~/.rtorrent.rc
    

    Add 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-config
    
  4. Test the installation

    julio@julio-acer ~> which rtorrent
    /home/julio/bin/rtorrent
    
julio@julio-acer ~> rtorrent

The screen should be colored. Press * to switch between collapsed view and expanded view.

More tips can be found here

Note: If you open rTorrent with GNU Screen and it complains about the number of colors in your terminal, add the following line to ~/.screenrc: term screen-256color.

I’ve had issues with the installation script due to version compatibility problems. In this case, you would need to downgrade several programs and run the script again.

Creating .torrent with mktorrent

In addition to downloading, sharing your files is also important. Keeping with the Unix program philosophy of simplicity, rtorrent does not have the function to create torrents.

For this task, I use mktorrent.

  1. Download mktorrent

    julio@julio-acer ~ $ sudo pacman -S mktorrent
    
  2. Move all files to be shared to a separate folder.

  3. Run the command with the appropriate parameters and options

    mktorrent -v -p -a="ANNOUNCE" -c="COMMENT" -n="NAME" -o="OUTPUT.torrent"
    

    Where

    • -v Verbose
    • -p makes the torrent private
    • ANNOUNCE is the URL provided by the tracker
    • COMMENT is a comment about the torrent
    • NAME is the package name, which will be in the metainfo. It’s better to leave it empty to avoid changing folders.
    • OUTPUT is 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, meaning to upload the same files to different trackers, rtorrent will return the error “Info hash already used by another torrent.” To solve this problem by making the hashes different, it can be done in the following ways:

  1. Add or modify a file when creating the second .torrent

  2. Set a different size for each piece using the -l parameter. Example:

    mktorrent -v -p -a "http://tracker.url/announce.php?passkey=123456xxxx&uid=xxxxx" -l 19 -o album_tracker2.torrent "Year_Folder - Disc"
    

Uses 512kb for each piece.


ruTorrent also allows for multi-user configuration, keeping each user’s files in specific folders (rutorrent/share/users/USERNAME/settings/).


iPhone:


Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus