check rtorrent version

Please note that you need a recent version of rtorrent for magnet links to work.

rtorrent version used in these examples:

sudo dpkg -l rtorrent
ii rtorrent 0.8.9-2 ncurses BitTorrent client based on LibTorrent from rakshasa

Prepare rtorrent directory structure

The following structure will allow you to keep files in order.

mkdir ~/bittorrent
mkdir ~/bittorrent/incoming
mkdir ~/bittorrent/pending
mkdir ~/bittorrent/watch

Later we will configure ~/rtorrent.rc to automatically detect new torrent files added in the directory ~/bittorrent/watch

Use following options in file ~/.rtorrent.rc

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum number of simultanious uploads per torrent.
max_uploads = 5
# Global upload and download rate in KiB. "0" for unlimited.
download_rate =
upload_rate = 10

# Default directory to save the downloaded torrents.
directory = ./incoming

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

change working directory into ~/bittorrent

To use the directory structure we created and configured, we should “cd ~/bitorrent”

( or we can use full path directories in the ~/.rtorrent.rc )

cd ~/bittorrent
rtorrent

You can use following bash script to download a magnet link.

#!/bin/bash
## usage: ./download_magnet_url.sh "magnet_link"
## magnet link shoul be enclosed in quotes.

cd ./watch # set your watch directory here
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"

use the script as following

replace “magnet_link” with the real link.

cd ~/bittorrent
./download_magnet_url.sh "magnet_link"