blog and things oh hi there!
Adding torrents to ruTorrent with PHP

While using ruTorrent, I was looking for a way to add torrents through PHP directly to the ruTorrent WebUI. Here is a simple way to do this using guzzle.

First install guzzle through Composer. This is what goes in composer.json:

    "require": {
        "guzzlehttp/guzzle": "^6.2"

And here is the guzzle request that posts the torrent file.

require __DIR__.'/vendor/autoload.php';
use GuzzleHttp\Client;

try {
    $guzzle = new Client;
    $response = $guzzle->post(
        'https://server.address/rutorrent/php/addtorrent.php', [
        // if using basic auth, place credentials here
        'auth'      => ['username', 'password'],
        'multipart' => [[
                'name'     => 'torrent_file',
                'contents' => file_get_contents('path/to/torrent/file'),
                'filename' => 'filename.torrent',
} catch (Exception $e) {
    throw new Exception($e->getMessage());
© 2020 Kevin Jung