Freebsd下 跑 BT client (bittornado)

因為我打掃好像手賤,搞錯了不要的光碟包,和要的光碟包
似乎把要的光碟包給丟了……….
所以想用bt 來抓 xp 的。就search了一下

看到似乎有一個叫bittornado 的ports能用
裝好後,就能用了

參考如下文章

http://web.archive.org/web/20040630035733/http://sogono.com/carlo/linuxtorrent/

Downloading Torrents in Linux and Unix
Carlo Sogono
cs83<at>uow.edu.au
Version 1.02 – 29 May 2004


Introduction

This simple guide explains how to get the Python version of BitTornado working in the command line interface.

Reasons why you might like to use the command line version to instead of the GUI ones:

  1. The command line version does not need the GUI so it’s possible to download torrents even without X running.
  2. You can run torrents remotely through telnet/ssh. This is great if you have personal home servers or would like to download torrents using your office computer from home. 😛
  3. It is possible to put the torrent window in the background then load the same window from any terminal, be it remotely using telnet/ssh, locally or via an X console. I will show you how this works in a while.
  4. The command line version simply uses less resources.

What you need:

  • BitTornado
  • Python – installed on most Linux distributions; check BitTornado requirements for details
  • NCurses library – installed on most Linux distributions
  • GNU screen (though the regular Unix ‘screen’ might work) – this is installed on most Linux distributions; to check type ‘screen –help’

Assumed knowledge:

  • You know what the hell torrents are and how they work
  • Basic Unix knowledge, specifically with the command line
  • Know how to configure port redirection (and have already done so) if your system is behind a firewall

Normal BitTornado usage

Extract the tarball and you will see several files inside the package including btdownloadcurses.py which we will use in this guide. Try looking at the options by typing ./btdownloadcurses.py. You will notice several options but pay particular attention to max_upload_rate to set your maximum upload rate in kilobytes. This is important especially for broadband users who have upload rates lower than their download rates. You wouldn’t want to use 100% of you upload rate because that would slow down not only your uploads but regular downloads as well.

To run BitTornado from a regular terminal you would run it by executing something like this:

$ ./btdownloadcurses.py –max_upload_rate 16 download-me-now.torrent

This would open the torrent file download-me-now.torrent, upload at a maximimum of 16 kilobytes/second and use the current terminal for displaying the text-based (curses) status.

This is what it should look like:

To quit, just press ‘q’.

Using GNU Screen with BitTornado

This is probably the main reason why you would want to use the command line version of BitTorrent.

When you run BitTornado the usual way using a Unix terminal, the program has to run with that particular terminal during the whole duration of the download. If the terminal is closed abruptly or is killed, BitTornado closes with it. In programming lingo, this happens because the current stdout was closed. Your only option is actually keep this terminal running until the download finishes.

Running the GUI or X version is probably even more useless in this regard unless you use something like VNC but that just takes too much resources in my opinion. You cannot view your download remotely or quit your X session without interrupting the download. I use a slow P3 with 64MB RAM as my file/development server and I don’t need to run X just for the sake of downloading torrents.

Now what?

Use GNU screen or the regular Unix screen program. Screen is basically a terminal emulator which you can throw to the background and then load in another terminal. When you run your downloads with screen, it’s possible to view the terminal remotely through telnet/ssh, your default terminal in your system’s monitor or in an X terminal without disrupting the download.

To use screen, just prefix your download line with ‘screen’ like so:

$ screen ./btdownloadcurses.py –max_upload_rate 16 download-me-now.torrent

After this, you will see the regular download terminal, as if you ran btdownloadcurses.py directly. To throw this screen to the background without interrupting your download, press the sequence “Ctrl-A D”. You will get a response in your terminal similar to this one:

$ screen ./btdownloadcurses.py –max_upload_rate 16 download-me-now.torrent
[detached]
$

Now you’re back at the prompt.. You can run screen as many times as you wish, you can even run several torrent downloads at the same time. To query screen and the active terminals, just type:

$ screen -list
There are screens on:
1620.pts-0.dilemma (Detached)
214.pts-0.dilemma (Detached)
2 Sockets in /home/cs83/.screen.

As you can see, there are two terminals running in the background. The numbers at the start of each line is the PID of the screen instance you’re running. You can check this by doing ps -ef | grep 1620 on your terminal. If you only ran one screen terminal, you can just reaload or “attach” the screen with the ‘-r’ option:

$ screen -r

However, when there are 2 or more running, you would have to run screen -list first then include the screen ID while running screen.

$ screen -r 1620.pts-0.dilemma

This will load screen with PID 1620 to your current terminal. Normally, the higher the PID number, the later it was executed. So this means PID 1620 was probably the most recent screen you executed. When you attach a screen and view the list again, it would look like this now:

$ screen -list
There are screens on:
1620.pts-0.dilemma (Attached)
214.pts-0.dilemma (Detached)
2 Sockets in /home/cs83/.screen.

This means that screen terminal 1620 is being viewed in another terminal window. You can attach/detach in any terminal, including one inside X. The beauty of screen with BitTornado is being able to start the download anywhere and check the download also anywhere.

Some Helpful Scripts

I have created scripts to make attaching and detaching torrent terminals easy. Note that I have only tested these scripts using Slackware Linux 9.1 running Bash. These scripts might work with the regular Bourn shell (sh) but I make no guarantees.

This first Bash script is called bt. All you need to do is add the torrent name as an argument and it runs screen automatically like so:

$ bt download-me-now.torrent

Here’s the script:

#!/usr/bin/bash
#
# bt – run BitTornado with screen
# Written by Carlo Sogono cs83 <at> uow <dot> edu <dot> au
#

which screen 1>/dev/null 2>/dev/null
if test $? = 1
then
echo “Error: The application ‘screen’ cannot be found in the system”
exit 1
fi

# Default maximum upload rate if nothing is specified in the command line
MAXRATE=3

if test -z $1
then
echo Error: No torrent file specified
echo ‘Usage: bt <file> [upload rate in kilobytes/second]’
exit 1
elif test ! -z $2
then
MAXRATE=$2
fi

screen /path-to-BitTornado/btdownloadcurses.py –max_upload_rate $MAXRATE $1

Make sure you edit this script by putting your path to BitTornado and setting your desired max_upload_rate value.

The next Bash script is called scr. It makes attaching and querying screen terminals a lot easier by assigning job IDs to each screen. Here’s how to view the running screen terminals:

$ scr
Job Screen ID
1 1658.pts-0.dilemma
2 214.pts-0.dilemma

Here’s now to attach screen PID 1658 with assigned job 1:

$ scr 1

To detach, do the usual “Ctrl-A D” sequence.

Here is the script:

#!/usr/bin/bash
#
# scr – load screen jobs
# Written by Carlo Sogono cs83 <at> uow <dot> edu <dot> au
#

which screen 1>/dev/null 2>/dev/null
if test $? = 1
then
echo “Error: The application ‘screen’ cannot be found in the system”
exit 1
fi

ITER=1
if test -z $1
then
printf “JobtScreen IDn”

for I in `ls ~/.screen`
do
printf ” %dt%sn” $ITER $I
ITER=$((ITER+1))
done
else
FOUND=0

for I in `ls ~/.screen`
do
if test $ITER = $1
then
screen -r $I
FOUND=1
break
fi

ITER=$((ITER+1))
done

if test $FOUND = 0
then
echo “Error: Screen job $1 does not exist”
exit 1
fi
fi

IMPORTANT! Make sure you put these two scripts in a directory in your PATH. You may put it in /usr/bin or /usr/local/bin and make them executable:

$ chmod a+x bt scr

That’s it! Happy downloading!

———–我從man身上找到的———————-

BTDOWNLOADCURSES(1) User Commands BTDOWNLOADCURSES(1)

NAME
Btdownloadcurses – curses bittornado download interface

SYNOPSIS
btdownloadcurses <global options>

DESCRIPTION
Curses interface to download torrents.

OPTIONS
This program follows the usual GNU command-line syntax, with long
options starting with two dashes (‘-‘). A summary of options is
included below.

–max_uploads number

the maximum number of uploads to allow at once. (defaults to 7)

–keepalive_interval seconds

number of seconds to pause between sending keepalives (defaults
to 120.0)

–download_slice_size bytes

How many bytes to query for per request. (defaults to 16384)

–upload_unit_size bytes

when limiting upload rate, how many bytes to send at a time
(defaults to 1460)

–request_backlog number

maximum number of requests to keep in a single pipe at once.
(defaults to 10)

–max_message_length length

maximum length prefix encoding you’ll accept over the wire –
larger values get the connection dropped. (defaults to 8388608)

–ip ip

ip to report you have to the tracker. (defaults to ”)

–minport portnum

set portnum as the minimum port to listen on, counts up if
unavailable (defaults to 10000)

–maxport portnum

set portnum as the maximum port to listen on (defaults to 60000)

–random_port 0 | 1

whether to choose randomly inside the port range instead of
counting up linearly (defaults to 1)

–responsefile file

file the server response was stored in, alternative to url
(defaults to ”)

–url URL

URL to get file from, alternative to responsefile (defaults to
”)

–selector_enabled 0 | 1

whether to enable the file selector and fast resume function
(defaults to 1)

–expire_cache_data days

the number of days after which you wish to expire old cache data
(0 = disabled) (defaults to 10)

–priority -1|0|1|2[,-1|0|1|2]

a list of file priorities separated by commas, must be one per
file, 0 = highest, 1 = normal, 2 = lowest, -1 = download dis-
abled (defaults to ”). Order is based on the file/torrent order
as shown by btshowmetainfo. For example, to download only the
third of four files use: –priority -1,-1,2,-1

–saveas filename

local filename to save the file as, null indicates query user
(defaults to ”)

–timeout seconds

time in seconds to wait between closing sockets which nothing
has been received on (defaults to 300.0)

–timeout_check_interval seconds

time to wait in seconds between checking if any connections have
timed out (defaults to 60.0)

–max_slice_length length

maximum length slice to send to peers, larger requests are
ignored (defaults to 131072)

–max_rate_period seconds

maximum amount of time in seconds to guess the current rate
estimate represents (defaults to 20.0)

–bind ip[,hostname]

comma-separated list of ips/hostnames to bind to locally
(defaults to ”)

–ipv6_enabled 0 | 1

allow the client to connect to peers via IPv6 (defaults to 0)

–ipv6_binds_v4 0 | 1

set if an IPv6 server socket will also field IPv4 connections
(defaults to 1)

–upnp_nat_access 0 | 1 | 2

attempt to autoconfigure a UPnP router to forward a server port
(0 = disabled, 1 = mode 1 [fast], 2 = mode 2 [slow]) (defaults
to 1)

–upload_rate_fudge seconds

time equivalent in seconds of writing to kernel-level TCP
buffer, for rate adjustment (defaults to 5.0)

–tcp_ack_fudge overhead

how much TCP ACK download overhead to add to upload rate calcu-
lations (0 = disabled) (defaults to 0.029999999999999999)

–display_interval seconds

time in seconds between updates of displayed information
(defaults to 0.5)

–rerequest_interval seconds

time to wait, in seconds, between requesting more peers
(defaults to 300)

–min_peers number

minimum number of peers to not do rerequesting (defaults to 20)

–http_timeout seconds

number of seconds to wait before assuming that an http connec-
tion has timed out (defaults to 60)

–max_initiate number

number of peers at which to stop initiating new connections
(defaults to 40)

–check_hashes 0 | 1

whether to check hashes on disk (defaults to 1)

–max_upload_rate kB/s

maximum kB/s to upload at (0 = no limit, -1 = automatic)
(defaults to 0)

–max_download_rate kB/s

maximum kB/s to download at (0 = no limit) (defaults to 0)

–alloc_type normal | background | pre-allocate | sparse

allocation type (may be normal, background, pre-allocate or
sparse) (defaults to ‘normal’)

–alloc_rate MiB/s

rate (in MiB/s) to allocate space at using background allocation
(defaults to 2.0)

–buffer_reads 0 | 1

whether to buffer disk reads (defaults to 1)

–write_buffer_size space

the maximum amount of space to use for buffering disk writes (in
megabytes, 0 = disabled) (defaults to 4)

–snub_time seconds

seconds to wait for data to come in over a connection before
assuming it’s semi-permanently choked (defaults to 30.0)

–spew 0 | 1

whether to display diagnostic info to stdout (defaults to 0)

–rarest_first_cutoff number

number of downloads at which to switch from random to rarest
first (defaults to 2)

–rarest_first_priority_cutoff number

the number of peers which need to have a piece before other par-
tials take priority over rarest first (defaults to 5)

–min_uploads number

the number of uploads to fill out to with extra optimistic
unchokes (defaults to 4)

–max_files_open number

the maximum number of files to keep open at a time, 0 means no
limit (defaults to 50)

–round_robin_period seconds

the number of seconds between the client’s switching upload tar-
gets (defaults to 30)

–super_seeder 0 | 1

whether to use special upload-efficiency-maximizing routines
(only for dedicated seeds) (defaults to 0)

–security 0 | 1

whether to enable extra security features intended to prevent
abuse (defaults to 1)

–max_connections number

the absolute maximum number of peers to connect with (0 = no
limit) (defaults to 0)

–auto_kick 0 | 1

whether to allow the client to automatically kick/ban peers that
send bad data (defaults to 1)

–double_check 0 | 1

whether to double-check data being written to the disk for
errors (may increase CPU load) (defaults to 1)

–triple_check 0 | 1

whether to thoroughly check data being written to the disk (may
slow disk access) (defaults to 0)

–lock_files 0 | 1

whether to lock files the client is working with (defaults to 1)

–lock_while_reading 0 | 1

whether to lock access to files being read (defaults to 0)

–auto_flush minutes

minutes between automatic flushes to disk (0 = disabled)
(defaults to 0)

SEE ALSO
bittorrent-downloader(1), bittorrent-multi-downloader(1), btdownload-
gui(1), btdownloadheadless(1).

AUTHOR
This manual page was written by Micah Anderson <micah@riseup.net>, for
the Debian GNU/Linux system (but may be used by others).

btdownloadcurses (bittornado) August 2004 BTDOWNLOADCURSES(1)

在〈Freebsd下 跑 BT client (bittornado)〉中有 2 則留言

  1. 自動引用通知: Olivia

  2. 自動引用通知: Joshua

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料