MandrivaUsers.org : bittorrent from the command line howto - MandrivaUsers.org

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

bittorrent from the command line howto useful for doing it remotely

#1 User is offline   papaschtroumpf 

  • MUB Addict
  • Group: Members
  • Posts: 556
  • Joined: 14-June 04

Posted 24 August 2004 - 11:01 PM

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.

This post has been edited by papaschtroumpf: 13 September 2004 - 03:53 PM

Mandriva 2007 Spring - KDE - Athlon XP2100+ OC'd @ 2700+ - AK35GT2 (KT266A) motherboard - GeForce 2 Ultra
0

#2 User is offline   psycodelicmonti 

  • New Here
  • Group: New here
  • Posts: 1
  • Joined: 06-September 04

Posted 06 September 2004 - 05:06 PM

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:/>
0

#3 User is offline   Darkelve 

  • half-geek
  • Group: Members
  • Posts: 2,519
  • Joined: 13-April 03

Posted 06 September 2004 - 05:17 PM

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

This post has been edited by Darkelve: 06 September 2004 - 05:18 PM

0

#4 User is offline   papaschtroumpf 

  • MUB Addict
  • Group: Members
  • Posts: 556
  • Joined: 14-June 04

Posted 02 June 2005 - 05:04 PM

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...entfile.torrent
screen btdownloadcurses.py --display_interval 5 --url http://some.site.com...entfile.torrent
Mandriva 2007 Spring - KDE - Athlon XP2100+ OC'd @ 2700+ - AK35GT2 (KT266A) motherboard - GeForce 2 Ultra
0

#5 User is offline   scarecrow 

  • Platinum
  • Group: Platinum
  • Posts: 5,157
  • Joined: 16-February 05

Posted 02 June 2005 - 06:38 PM

Use Azureus- it has a remote, java based UI (accessible via your browser)
Alternatively, you may compile the XBT client port for Linux ( http://xbtt.sourceforge.net/ ) and control it via your running (?) Apache server and PHP.
0

#6 User is offline   SoulSe 

  • Glitched
  • View blog
  • Group: Global Moderator
  • Posts: 4,308
  • Joined: 11-November 02

Posted 03 June 2005 - 06:51 PM

Thanks papa!
Posted Image
"By all means let's be open-minded, but not so open-minded that our brains drop out." -Richard Dawkins
0

#7 User is offline   SoulSe 

  • Glitched
  • View blog
  • Group: Global Moderator
  • Posts: 4,308
  • Joined: 11-November 02

Posted 17 June 2005 - 06:12 PM

The much requested man pages for btdownloadcurses.
Posted Image
"By all means let's be open-minded, but not so open-minded that our brains drop out." -Richard Dawkins
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users