< Day Day Up > 

The BitTorrent protocol implements a hybrid client/server and P2P (page 891) 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.


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.

The BitTorrent program is available from www.bittorrent.com. 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 (908) 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.


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. Some of these clients are available on sourceforge.net.

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] 


 $ 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. Because the command line is long, it is broken by a backslash (\). Make sure no character follows the backslash, or else the backslash will not quote the following RETURN and the command will fail. (The shell supplies the > on the second line.)

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

The preceding 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 _ 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 CONTROL-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. (The shell supplies the > on the second line, you do not enter it.)

 $ 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                                                         | |                                                                              |  ------------------------------------------------------------------------------  

     < Day Day Up > 

    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    ISBN: 131478230
    EAN: N/A
    Year: 2005
    Pages: 213

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net