source/_posts/2013-12-25-download-torrents-on-your-server.markdown
f3cc705b
 ---
 layout: post
 title: "Download torrents on your server"
 date: 2013-12-25 22:34
 comments: true
 categories: [server]
 cover: /images/cover/avatar.png
 keywords: transmission, torrent, server, remote, rsync, firewall
 description: Setup transmission client on server
 ---
 
 ### tl;dr
5479dd33
 * How to setup Transmission web client on your Linux server
f3cc705b
 * Firewall setup
 * Email notifications setup
 
 # Why am I doing this?
 
 Recently I've needed to download some stuff from torrentz. I have quite
 unstable and slow internet connection at home, so I've decided to 
 download the stuff to my server and later transfer it to my laptop via
 rsync (with transfer resume enabled and high compression ratio).
 
 # Choose a torrent client
 
 There are [many](http://alinuxblog.wordpress.com/2010/09/14/top-10-torrent-clients-for-linux/)
 torrent clients suitable for headless Linux server (so they don't 
 need X.Org server and allow remote access). I've picked out [Transmission](http://www.transmissionbt.com/).
 It looks easy to configure & use, supports magnet links, is lightweight, 
 has web interface and is actively developed.
 
 # Install & configure
 
 If your Linux distribution provides split Transmission package, you need just
 transmission-cli or transmission-daemon (simply, ignore GTK or Qt packages).
 
 After installation edit Transmission daemon configuration file (may be located
 here ```/var/lib/transmission/.config/transmission-daemon/settings.json``` or 
 here ```/etc/init.d/transmission-daemon/settings.json```). 
 
 Interesting options you'll probably need to edit are these:
 
 * encryption: 2 (Require encrypted connections)
 * rpc-enabled: true (Required for Transmission web client)
 * rpc-password: "" (Put some password, after transmission-daemon restart it will be
 hashed)
 * rpc-port: 9091
 * rpc-whitelist-enabled: false (if you have dynamic public IP address you want disable this option)
 * umask: 0 (Give access to downloaded files to everybody -- files have read & write permissions for owner, group and others)
 
 If you're a bitch and want to disable seeding right after torrent download is completed,
 set ```ratio-limit``` to ```0``` and ```ratio-limit-enabled``` to ```true```.
 
5479dd33
 # Try web interface
 
 You don't need any HTTP server like Apache or Nginx, just go to http://your_domain:9091.
 Enter login username (by default empty) and password. That's all.
 
 {% img fancybox /images/transmission.png Transmission web client %}
 
f3cc705b
 # Open ports in your firewall
 
 Find ```peer-port``` option in transmission config. Open this port in ```/etc/iptables/iptables.rules```:
 
 	-A INPUT -p tcp -m tcp --dport 51413 -j ACCEPT
 	-A OUTPUT -p tcp -m tcp --sport 51413 -j ACCEPT
 	-A OUTPUT -p udp -m udp --dport 80:60000 -j ACCEPT
 
 Port 51413 has to be opened otherwise Transmission cannot download and upload
 data. Also I've opened a range of UDP ports because of magnet links.
 
 # Hey! Downloading is finished!
 
 Transmission daemon can run any script after downloads are completed.
 First I've set ```script-torrent-done-enabled``` to ```true``` and inserted
 full path to the script into ```script-torrent-done-filename``` option.
 
 Here's my script:
 
 {% codeblock lang:bash %}
 #!/usr/bin/env bash
 echo "'$TR_TORRENT_NAME' is finished!" | gnu-mail -a "From: cinan.remote@gmail.com" -s "Torrent download finished" cinan6@gmail.com
 {% endcodeblock %}