Linux.com

Feature

BitTorrent for Linux

By Mark Sobell on September 13, 2005 (8:00:00 AM)

Share    Print    Comments   

The BitTorrent protocol implements a hybrid client/server and P2P file transfer mechanism. BitTorrent efficiently distributes large amounts of static data, such as installation ISO images. It can replace protocols such as anonymous FTP, where client authentication is not required. Each BitTorrent client that downloads a file provides additional bandwidth for uploading the file, reducing the load on the initial source. In general BitTorrent downloads proceed more rapidly than FTP downloads.

This article is excerpted from the newly published book A Practical Guide to Linux Commands, Editors, and Shell Programming .

Unlike protocols such as FTP, BitTorrent groups multiple files into a single package called a torrent. For example, you can typically download several installation ISO images as a single torrent.

Like other P2P systems, BitTorrent does not use a dedicated server. Instead, the functions of a server are performed by the tracker, peers, and seeds. The tracker allows clients to communicate with each other. A client -- called a peer when it has downloaded part of the torrent and a seed once it has downloaded the entire torrent -- acts as an additional source for the torrent. As with a P2P network, each peer and seed that downloads a torrent uploads to other clients the sections of the torrent it already has. There is nothing special about a seed: It can be removed at any time once the torrent is available for download from other seeds.

After you download and install BitTorrent, the first step in downloading a torrent using BitTorrent is to locate or acquire a .torrent file. A .torrent file contains the information about the torrent, such as its size and the location of the tracker. You can use a .torrent file using its URI or you can acquire it via the Web, an email attachment, or other means. The next step is for the BitTorrent client to connect to the tracker to learn the locations of other clients that it can download the torrent from.

Once you have downloaded a torrent, it is good manners to allow BitTorrent to continue to run so other clients can upload at least as much information as you have downloaded.

Prerequisites

If no BitTorrent RPM file exists for your version of Linux, use an RPM file for a similar version. Because BitTorrent is written in Python and runs on any platform with a Python interpreter, it is not dependent on system architecture. The "noarch" in the name of the RPM file stands for no architecture.

To run, BitTorrent requires Python, which is installed as /usr/bin/python on many systems. Python is available in the python RPM package.

How BitTorrent works

The official BitTorrent distribution includes three client applications. You can use any of these applications to download BitTorrent files:

  • btdownloadheadless.py -- A text-based client that writes the status to standard output. Good for unattended downloads where the output is redirected to a file.
  • btdownloadcurses.py -- A text-based client that provides a pseudographical interface. Good for attended downloads to machines not running a GUI.
  • btdownloadgui.py -- A graphical client.

In addition to the official clients, several other clients provide extra features.

Using BitTorrent

To use BitTorrent, first locate the .torrent file for the torrent you want to download. You can copy the .torrent file to the working directory (the first format shown below) or specify it with a --url option (second format). The simplest BitTorrent command lines have the following formats:

$ btdownloadheadless.py --responsefile tfile.torrent [--saveas savefile]

or

$ btdownloadheadless.py --url http://domain/tfile.torrent [--saveas savefile]

where tfile.torrent is the name of, or http://domain/tfile.torrent is the URI for, the .torrent file, and savefile is the location to save the torrent in. In the case of torrents containing a single file, the file is saved as savefile. For torrents containing multiple files, the files are saved in a directory named savefile. If you omit the --saveas argument, the files are saved in the name specified in the .torrent file. Because each of the btdownload*.py applications takes the same arguments, the preceding formats work for all three applications.

The next example shows how to download Fedora Core 3 ISO images. These large files take considerable time to download. To start the download, give the following command:

$ btdownloadheadless.py --max_upload_rate 8 --url http://torrent.dulug.duke.edu/heidelberg-binary-i386.torrent

This command uses a URI to specify a .torrent file and saves the downloaded files in a directory named heidelberg (the name of the Fedora release) as specified by the .torrent file.

The --max_upload_rate 8 option prevents BitTorrent from using more than 8 kilobytes per second of upstream bandwidth. BitTorrent usually gives higher download rates to clients that upload more, so feel free to increase this value if you have spare bandwidth. You need to leave enough free upstream bandwidth for the acknowledgment packets from your download to get through or your download will be very slow. By default the client uploads to a maximum of seven other clients at once. You can change this value by specifying the --max_uploads argument, followed by the maximum number of concurrent uploads you wish to permit. The default value of 7 is usually appropriate for typical broadband connections.

After you give the preceding command, the screen quickly fills with output that looks similar to the following:

saving:        heidelberg-binary-i386
percent done:  0.0
time left:     finishing in 27:09:04
download to:   /home/max/heidelberg-binary-i386
download rate: 32.9 KB/s
upload rate:   0.0 KB/s
share rating:  0.000 (0.0 MB up / 1.2 MB down)
seed status:   30 seen now, plus 1 distributed copies (2:81.5%, 3:23.0%, 4:2.1%)
peer status:   5 seen now

The file size is that of all the files you are downloading: four ISO images and several smaller files. To abort the download, press Ctrl-C. The download will automatically resume from where it left off when you download the same torrent to the same location again.

Use the following command to perform the same download as in the previous example, this time throttling the rate and number of uploads to values sensible for modem users.

$ btdownloadcurses.py --max_upload_rate 3 --max_uploads 2 --url http://torrent.dulug.duke.edu/heidelberg-binary-i386.torrent

The preceding command displays output similar to the following:

file:     heidelberg-binary-i386
size:     2,467,681,047 (2 GiB)
dest:     /home/max/heidelberg-binary-i386
progress: _________________________________________
status:   finishing in 6:40:42 (1.0%)
dl speed: 285.6 KB/s
ul speed: 2.6 KB/s
sharing:  0.009 (0.1 MB up / 15.1 MB down)
seeds:    29 seen now, plus 0 distributed copies (1:0.8%, 2:0.0%, 3:0.0%)
peers:    1 seen now

Share    Print    Comments   

Comments

on BitTorrent for Linux

Note: Comments are owned by the poster. We are not responsible for their content.

Phhhttt!

Posted by: Anonymous Coward on September 14, 2005 05:06 AM
In general BitTorrent downloads proceed more rapidly than FTP downloads.

On paper this statement is true but, in the real world the truth is far different. The truth is that Bittorrent offers more to those that offer more upload bandwidth. You could also say that Bittorrent penalizes those that restrict upload bandwidth.

The problem is that most broadband connections are asynchronous, meaning that the download bandwidth is higher than the upload bandwidth. This means that because of the cap on your broadband upload speed Bittorrent will max out at around 384Kbps down. Compared to a good FTP site that might offer 3Mbps download speeds, Bittorrent pales in comparison.

Now, many people will stick up for Bittorrent and say that it is not the fault of Bittorrent but rather the fault of the broadband provider. I say that this is disingenuous because Bittorrent is specifically targeted at broadband users, the people that are most likely to have asynchronous connections so, Bittorrent is intentionally designed to penalize its target audience.

#

Re:Phhhttt!

Posted by: Anonymous Coward on September 14, 2005 06:29 AM
In general BitTorrent downloads proceed more rapidly than FTP downloads.

I tried for days to get the new suse or slackware<nobr> <wbr></nobr>....avg speed, 39kb. My ftp is much faster.


Now, many people will stick up for Bittorrent and say that it is not the fault of Bittorrent but rather the fault of the broadband provider. I say that this is disingenuous because Bittorrent is specifically targeted at broadband users, the people that are most likely to have asynchronous connections so, Bittorrent is intentionally designed to penalize its target audience.

Well said! All I was able to come up with was "it sucks!"

#

Re:Phhhttt!

Posted by: Anonymous Coward on September 14, 2005 08:08 AM
Frankly, I don't know which sites you're trying to get your torrents from, but every time I download something like Knoppix, my download is limited by the speed of my DSL modem. I may be only uploading at 5-30KiB/sec, but I download 350KiB/sec nearly constantly. However, these torrents tend to be extremely seed rich, so finding a seeder that's willing to send you a chunk is not difficult. Seed poor networks, on the other hand, often exhibit the phenomenon you've observed. Since there are not enough seeds available, those who are uploading more than others get priority so they can become seeds earlier.

#

Re:Phhhttt!

Posted by: Stumbles on September 14, 2005 08:40 AM
That's good for you and it is the most common statement I hear from those who have no problems with BT.



OTOH, myself included along with many, many others have nothing but disdain for BT. This is after enduring endless amounts of, "it works great for me", "open ports x y z", etc. A good many people fight with this application, doing all sorts of dances, ample sprinking of hocus pokus incantations, blessings of the almighty correct port configuration that if we get it to work. All our efforts are rewarded with download speeds that hardly classify as dail-up.



You can justify all you like about how it might save on ftp/http resources, etal and you can pump it up till your blue in the face but IMO BT is one disappointing application.

#

Re:Phhhttt!

Posted by: Anonymous Coward on September 14, 2005 10:42 AM
Your kidding me right? Maybe someone that has their system locked down so completely that they can't run anything P2P without fiddling with ports and stuff... But not anyone that knows what the hell they are doing. I **am** on dialup, there are only two instances that I 'ever' fail to get better transfer rates, a) I something is keeping me from connecting to remote clients (this is usually a NAT issue, but can be cause by other things) or b) there isn't anyone around to download from. Usually, the result is a 4-5k/s upstream and 2-3k/s downstream, for 6-8k/s transfer rates, on a connection that I have never gotton better than 4k/s downloading from any FTP site, 'ever'. Also, a better client is a good idea. Bittorrent is extremely limited, obscure, had to work with and doesn't give you much (if any) control, let alone information. Using something like Azureus, you can get real information, tell what the problems are that keep you from getting a decent rate, etc. Oh.. And try downloading something legitimate, the illegitimate materials are probably going to come from people trying to steal half a dozen things at the same time, which means you might be getting 1% of their bandwidth. If you are downloading off of 50 people, you are likely lucky to get dial-up speeds, precisedly because of **what** you are downloading and what they are using their bandwidth for. If you don't have a $@#$ clue how it works or why the porn you are downloading from some idiot downloading a dozen pirated movies and applications isn't arriving at lightning speeds, then you haven't a leg to stand on when trying to complain that it doesn't work. Neither, under the same illegal use, does Kazaa or any other P2P system.

#

Re:Phhhttt!

Posted by: Brcha on September 14, 2005 06:06 PM

This is after enduring endless amounts of, "it works great for me", "open ports x y z", etc.




Good point. Not until recently I was connecting to the net using the connection of my university. The university network has a restrictive firewall and it allows me only outgoing connections through http proxy. Therefore, to be able to use BitTorrent, I had to tunnel all my connections using privoxy and tor. After that all my connections were anonymous (eventhough I never cared if my downloading of kubuntu iso are anonymous), and as a result, they were also much slower.

Now I am using cable modem and I still have some problems with BitTorrent (NAT), but at least, now I don't have to use tor (if I don't want to).

#

Re:Phhhttt!

Posted by: raindog on September 15, 2005 04:18 AM
I had nothing but trouble with the official BitTorrent application, but after I sucked it up and installed Java so I could run Azureus, everything got better. So there are problems with the various implementations of the protocol, but the protocol itself is working for the vast majority of users.

I remember when people were producing endless sharp criticism of FTP because it required a real life IP address and a bunch of open ports by default. People adapted, FTP adapted, it matured. The same will happen with BT.

#

Re:Phhhttt!

Posted by: Anonymous Coward on September 14, 2005 07:10 PM
"On paper this statement is true but, in the real world the truth is far different. The truth is that Bittorrent offers more to those that offer more upload bandwidth. You could also say that Bittorrent penalizes those that restrict upload bandwidth."

True, this is how peer to peer works, and cuts down on those that only "leech"

"The problem is that most broadband connections are asynchronous, meaning that the download bandwidth is higher than the upload bandwidth. This means that because of the cap on your broadband upload speed Bittorrent will max out at around 384Kbps down. Compared to a good FTP site that might offer 3Mbps download speeds, Bittorrent pales in comparison."

Alright... nope. The upload and download rate are proportional. If you upload at 5kbps, you might dl at 300 kbps (happens to me fairly often). It depends on the number of "seeders" and "peers" and how much bandwith is "up for grabs". if you allow all your upload bandwith to be consumed, it will cause some packet loss and slow down your overall download speed (since it is your upstream that says "hey, send me another packet I got this one... etc" . So it is a good idea to cap your bittorrent upload somewhere below your maximum.

As for it being faster than ftp... if the ftp has 4000+ users (one case) and can still deliver that speed, then go for ftp.

If you have broadband, bt is simpler. If you don't enjoy using your upstream bandwith (i.e. on dialup) I would recommened FTP for sure.

"Now, many people will stick up for Bittorrent and say that it is not the fault of Bittorrent but rather the fault of the broadband provider. I say that this is disingenuous because Bittorrent is specifically targeted at broadband users, the people that are most likely to have asynchronous connections so, Bittorrent is intentionally designed to penalize it""s target audience."

Alright repition... Ugh, oh no I can't take all I want without giving. This is the nature of BT, go to the home page, and look at the explanation for how it works. As for ports not working... allowing traffic through 6881-6999 does the trick everytime. If you can't change these values, then well you are out of luck without resorting to trickery...

Hopefully, this sets a precedent for real comments and not flame bait.

#

modem users

Posted by: Anonymous Coward on September 15, 2005 01:38 AM
I've held off on bitTorrent because its painful enough sucking down updates without having to give up some bandwidth for potential uploads. I have a 56 k modem but the telephone system here is so bad that I'm effectively 28.8. Hopefully bitTorrent doesn't become too popular before the 50% of us that *can't* have broadband finish waiting for the telephone companies to replace their lines.

#

When is it faster?

Posted by: Anonymous Coward on September 14, 2005 08:32 PM
Simple BitTorrent is faster when the guy who distributes a file does not have access to or cannot afford a ftp-server with a large enough bandwidth.

BitTorrent is thus an effective way to distribute material at a low cost. Of course the total cost of distributing material will also be lower as people will typically download material from a node in their vicinity.

#

"screen" is your friend

Posted by: Anonymous Coward on September 14, 2005 04:42 AM
<tt>screen</tt> comes handy for unattended use with <tt>btdownloadcurses.py</tt> pseudo graphical userinterface.

#

btlaunchmany

Posted by: Anonymous Coward on September 14, 2005 05:47 AM
Don't forget the multi-torrent commands:

btlaunchmany.py
btlaunchmanycurses.py

I used to use those bloated clients for multi-torrent support until I realized that these existed. oops<nobr> <wbr></nobr>:P

#

What a pointless arguement

Posted by: Anonymous Coward on September 14, 2005 08:44 AM
I mean, if you can use Snipe or Azuerus, who cares about the weak-assed python client?

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 14, 2005 09:52 AM
Its for people like you who can't figure out how to spell Azureus.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 14, 2005 01:18 PM
Those who want a curses interface (check on your torrents via ssh!) and lower CPU/memory overhead.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 14, 2005 01:34 PM
At this moment Azureus uses 1GB of memory on my computer.
Which causes everything too both start slow and run slow, it makes my Athlon64 3000+ with 1GB DDR-RAM (and because of azureus 3GBs of swap) feel like an old 500MHz.

I'd like to try another client, you mention "Snipe" is that a client? Google is of no help in finding it, do you have a link?

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 15, 2005 01:37 AM
Try QTorrent or KTorrent. I found QTorrent to be a LOT lighter than Azureus, and I didn't have to scale it's upload down as much (I guess it is less aggressive in its uploading than Azureus is). I haven't used KTorrent (haven't downloaded anything in a while), though the new version (still beta I think) look really nice, it has many of the features of Azureus.

If you prefer gtk apps you will have to ask someone else, same for console based.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 15, 2005 06:40 AM
I tried both (Yes, I use KDE), unfortunate neither can do the one thing that makes me stick too azureus.
Proritize individual files in a torrent, in azureus; if you don't want a file you set "Do not download" on it, if you want a file more then the others you set "High" prority on that file.
As far as I've read libtorrent have this feature, but no client I've seen using libtorrent has used that feature.
I should have mentionen that i original post.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 15, 2005 09:41 AM
KTorrent now has the "Do not download" option for files or directories. As a side note, It's amazing the speed KTorrent is developed. You get noticeable improvements every week. If it's some time since last you tried it, you should definitely check it out again.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 15, 2005 07:09 AM
Bittornado is your friend. Curses and GUI, up to you. Much more flexible.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 14, 2005 08:16 PM
I was getting NAT error with Azureus. But I have no problems with BitTorrent.

#

Re:What a pointless arguement

Posted by: Anonymous Coward on September 15, 2005 06:10 AM
there's always torrentflux too, <a href="http://www.torrentflux.com/" title="torrentflux.com">http://www.torrentflux.com/</a torrentflux.com>, a nice php/mysql web frontend that makes it easy to manage your torrents from remote locations. A little heavier than the cli python stuff but prettier and more useful in my opinion.

#

Enterprise

Posted by: Anonymous Coward on September 15, 2005 10:55 AM
I'll just run out and push bittorrent clients onto all my servers because linux.com (the enterprise linux resource) said it was good.

ahem. why do I keep coming back for more pointless articles.

#

Re:Enterprise

Posted by: Anonymous Coward on January 11, 2006 09:53 AM
With just some basic usage, I don't think we need to read a book/article like this.

#

Re:Enterprise

Posted by: Anonymous Coward on February 15, 2006 05:40 AM
was that sarcasm?

seems like a great idea for information that needs to be distributed, as it cuts down on bandwidth demands on the originating server. You can build your own tracker...

#

Re:Enterprise

Posted by: Administrator on June 10, 2006 08:05 AM
Dear Mark,
Thanks for your post. The info
on bittorrent I can find via google
is not very specific. In particular,
I have downloaded several rpms and checked
them, and none contain a file called btdownloadheadless.py.

Can you please post a story about bittorrent
with correct details if you have them?

Thanks.

#

BitTorrent for Linux

Posted by: Anonymous [ip: 82.150.169.28] on December 10, 2007 07:40 AM
well, bittorrent is fast, even behind nat. I'm behind a nat without access to port map and everything is same fast as turbo-fast http download... just take a look

http://bayimg.com/bAihEAabB

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya