How to serve files with a simple and quick PHP BitTorrent tracker

I needed to share some raw video files with a friend lately so I uploaded 17GB of data to my webserver and sent them the HTTP link. Problem was the video files were scattered over several directories and the directory structure was important so the end user would have had to download each one individually if they didn’t have some sort of download manager to download all. I could have given them anonymous FTP access but the end user isn’t that technical so I had to keep it as simple as possible. I could have zipped up the files on the server but that was taking ages for 17GB and would be a disaster if somehow the big ZIP file corrupted.

So I decided to make a torrent of the data. The great thing about torrents is nearly everybody knows how to use them no matter how technophobic they are as they all want to download Game of Thrones every Monday morning. I already have rtorrent and mktorrent on my Linux server so I already had a way to seed and a way to create the actual torrent files. I was just missing a tracker. I wanted the quickest and simplest option, and I found it in Bitstorm via an article on TorrentFreak.

You can download BitStorm’s one file of PHP source here.

1) Save as ui.php and upload to your web server to a publicly accessible folder. So your URL should be something like http://www.georgiecasey.com:80/ui.php
Notice the port number of 80, the standard HTTP port. You need to specify this in your torrent files as a BitTorrent tracker can be on any port and won’t default to 80.
2) Change permissions so script has write access to /dev/shm/ to track peers. So chmod 0755 ui.php or something like that.
3) Create the torrent file of the folders you want to transfer with mktorrent and the announce URL of your ui.php file. eg mktorrent --announce=http://www.georgiecasey.com:80/ui.php folder_of_files/
4) Start a rtorrent instance where your folder_of_files is and add your new torrent. It should do a hash check and start seeding. It’s best to open rtorrent in a screen so you can leave it running.
5) Send the torrent to whoever you want to download the files.

Damn, it feels weird using BitTorrent in legal ways!

Leave a Reply

Your email address will not be published. Required fields are marked *