Jump to content

bittorrent from the command line howto


papaschtroumpf
 Share

Recommended Posts

I've seen lots of questions about bittorrent on this board, in fact maybe this post should make it in the FAQ. Note DarkElve pointed out that he had another post on bittorrent in the GUI, so I grabbed some of the info from his posted and added it here, so some of the credit goes to him too.

 

*** What is Bittorrent? ***

Bittorrent is a distributed P2P file sharing client, used for "swarming [big] downloads across unreliable networks". When you download a file using Bittorrent, you also provide the parts you already downloaded for others to upload. You have to provide just as much upload as you've downloaded, so that everyone gets treated on an equal basis.

 

Advantages: you can get extremely high download rates and the file gets constantly checked for errors, so it will be extremely unlikely you will end up with a broken download. A 200MB-file could very well be finished within a couple of hours.

 

Disadvantages: This is mostly used for the newer/newest stuff, so chances are after a while you won't find previous versions of a file/series because everyone already downloaded it. This is why Bittorrent is mostly used for getting the latest movie/anime from the net. Also a lot of Linux ISO's are available. More info: http://bitconjurer.org/BitTorrent/

*** END ***

 

One way to retrieve bit torrents is to use a GUI based client, like the default btdownloadgui.py or something more fancy like Azureus. (if this post gets stickied in the FAQ, I'll volunteer to add details about gui based downloading).

 

I wanted a way to start and control torrent downloads remotely (understand "from work") over ssh, so I looked at the command line version of bittorrent. This worked well however the torrent would abort if I closed the ssh session, or I wouldn't have access to the session once I got home, so I looked into the "screen" command. Combining the two provided a solution that perfectly met my needs and I'm outlining it here.

 

First you need to install the bittorrent command line clients: urpmi bittorrent

You may also have to install Python, although it came installed with my Mandrake10 Powerpack so I didn;t go through that step.

 

The bittorent package provides 2 python scripts: btdownloadheadless.py and btdownloadcurses.py.

 

You can also install bittorrent-gui (urpmi bittorrentgui) to install the script downloadgui.py which is what gets launched by default when you click on a .torrent file in your browser and provides a very basic gui interface (basically the same as with the default client under Windows)

 

btdownloadheadless.py outputs results periodically in the console (every .5s by default!)

 

btdownloadcurses.py uses the curses library to "redraw" the current status of the download using characters.

 

 

btdownloadcurses.py suits my style best, so it is what I will be using here, although you can use the same recipe for btdownloadheadless.

 

First try out btdownloadcurses on the command line (either the console or an ssh session) to see what it does. locate the URL to a torrent file, say http:/this_is_a_url/MyTestTorrent.torrent and simply type btdownloadcurses.py http:/this_is_a_url/MyTestTorrent.torrent

You should see something like this:

 ------------------------------------------------------------------------------
| file:     MyTestTorrent                                                      |
| size:     527,543,812 (503.1 MB)                                             |
| dest:     /home/papaschtroumpf/torrents/MyTestTorrent                        |
| progress: ###_______________________________________________________________ |
| status:   finishing in 5:08:28 (5.8%)                                        |
| speed:     44.2 KB/s down -  67.3 KB/s up                                    |
| totals:    29.4 MB   down -  55.0 MB   up                                    |
| error(s):                                                                    |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
------------------------------------------------------------------------------

 

since we're running over ssh, there is no need to update the screen so often, it just consumes a bunch of bandwidth, so we could start over by adding the --display_interval command line argument, for example to update the screen only every 5s:

btdownloadcurses.py --display_interval 5 http:/this_is_a_url/MyTestTorrent.torrent

 

 

There are lots of other command line options but the defaults appear to work for me. For details on command line options type "man bittorrentgui". This seems to work in mdk 10 (OE at leat) but the man page is not available with all bittorrent rpms so if you don't have it, check out http://annys.eines.info/cgi-bin/man/man2ht...rent-downloader or use google and search for man btdownloadcurses (the command line options are the same for the 3 python scripts)

 

In particular you may be interested in the --saveas option to rename the file downlaoded and the --limit_upload_rate option if you don't want the torrent to consume all of your available bandwidth.

 

If you close your console or terminate your ssh session, the torrent will stop downloading because the script will stop. You can always restart where you left off by re-issuing the command above, but there is a better way:

 

Enters the screen command. Basically it allows you to "detach" a screen from the window you started it in, and re-attach it later to the same window or another one.

Simply use "screen" in front of the previous command:

 

screen btdownloadcurses.py --display_interval 5 http:/this_is_a_url/MyTestTorrent.torrent

 

You shouln't see any difference from running it without the screen command.

Now press "Ctrl-A" followed by "d": this is the magic key combination to detach btdownloadcurses.py from the current window: the program hasn't stopped, it simply stopped using the console or ssh window.

 

close your window or you ssh session. If you simply close the ssh or console window without detaching first, the detach operation still occurs automagically.

 

Now open a new console or ssh session.

 

Type screen -r this is the command to re-attach the detached screen to your current console: you now see you torrent download is still in progress and has been downloading "behind the scenes".

 

If you have started several torrents as detached screens, you can type screen -ls to list the detached screens available on your machine. Then type screen -d -r the_screen_name where the_screen_name is one of the names listed by the previous command that you want to re-attach.

 

There is much more to the screen command, so refer to its (huge) man page if you need more details. There are lots more magic key pressed than "Ctrl-A d", for example "Ctrl-A K" kills the current scren altogether. The key commands can also be remapped if you like.

 

 

Finally, it's a lot of typing anda lot to remember so rather than type everything every time, I created an alias in my ~/.bashrc file:

alias gettorrent='screen btdownloadcurses.py --display_interval 5';

 

then I can just type gettorrent http:/this_is_a_url/MyTestTorrent.torrent at the command line (and since I generally get the URL through cut and paste, it's very little typing).

 

Note that I have ran into torrents that use a "compact" tracker. bittorrent-3.3 which is installed with mdk 10.0 doesn't support the compact trackers. Google for bittorrent-3.4.2-1mdk and bittorrent-gui-3.4.2-1mdk packages or above.

 

Hope you found this tip useful.

Edited by papaschtroumpf
Link to comment
Share on other sites

  • 2 weeks later...
Guest psycodelicmonti

Top!

 

Thanks for that, sorted me nicely. Especially the screen command thingy. Thought there must have been something to keep programs running in the background.

 

:thanks:

Link to comment
Share on other sites

papaschtroumpf, there is a FAQ about bittorent from CLI already, by myself :)

 

I'm not pretending it is better, but either merge it with the information I have given or replace it by this explanation. If no extra information is lost, I would not mind my explanation being replaced by this article.

 

 

Darkelve

Edited by Darkelve
Link to comment
Share on other sites

  • 8 months later...

When I wrote this originally there the bittorrent client seemed to be smart enough to detect if the argument passed was a torrent file or a torrent URL.

This has changed in more recent versions and you need to specify --url on the command line if you are passing it a url:

 

if the .torrent file is in the current directory on your drive:

screen btdownloadcurses.py --display_interval 5 torrentfile.torrent

 

if the .torrent file is on the 'net at http://some.site.com/torrentfile.torrent

screen btdownloadcurses.py --display_interval 5 --url http://some.site.com/torrentfile.torrent

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...