Hi!请登陆

在linux下安装ctorrent下载种子文件

2020-10-31 60 10/31

VPS大家手里多多少少都会有那么一两个(win请绕道),如果能让他们在空闲的时候帮我们下载一些很大,但是又下载很慢的种子,岂不是一举两得!

linux命令行下的torrent下载软件真的很少([rc]Torrent和Transmission的命令行版本),而且实在不太好用(当然是和迅雷不能比)。

但是如果你看完此篇,也许会发现原来在命令行里下载种子其实不是那么难!

[TOC]

CTorrent

CTorrent:BitTorrent实现
CTorrent是一个国人写的C/C++实现的,小型的BitTorrent:CUI客户端,它对希望了解BitTorrent网络的朋友们提供了一个很好的模板。程序只有5000多行,使用了openssl/sha库。它实现了下列功能:

* 高速缓冲,缺省大小cfg_cache_size(btconfig.cpp).
* 带宽限制
* 解析Bencoding编码,可以用'-x'选项查看.torrent文件信息而不下载。
* 快速缓冲,使用'-b'选项。
* 制做.torrent文件

最NB的是CTorrent可以安装到你的路由器中,再插个U盘,很简单就能DIY一个离线下载!

Enhanced CTorrent

CTorrent的加强版!功能强大了很多,下载速度也是刚刚的!

后者虽然是加强版,但是在使用上几乎没有什么差别!

下载和安装

源代码下载

软件 官网 网盘地址 提取密码
CTorrent ctorrent.sourceforge.net 下载 dkw4
加强版 rahul.net/dholmes/ctorrent 下载 9tjx

编译

编译的命令很简单

./configure
make && make install

可能出现的问题

由于代码比较老,在编译的过程中可能会出现各种各样的错误,下面列举出来

configure: error:

C++ compiler cannot create executables

解决方法:

You need to install c++ on your computer. even if you installed gcc that doesn't automatically install g++. Try to run one of the following commands that fit your Linux distribution best 🙂
你需要安在你的系统安装C++。就算你装了gcc可能g++也没有自动安装。所以在你的linux发布版中运行一下下面的命令吧! :>

yum install gcc-c++
or
apt-get install gcc-c++
or
apt-get install g++

invalid conversion from const char to char*

解决方法:

在bencode.cpp里209行找到pn = strchr(p, PATH_SP); 将其改为 pn = (char *)strchr(p, PATH_SP); 即可!

fatal error: openssl/sha.h

没有那个文件或目录

解决方法:

缺少 openssl dev包,解决:安装libssl-dev

sudo apt-get install libssl-dev

PACKAGE_STRING was not declared in this scope

PACKAGE_BUGREPORT was not declared in this scope

解决方法:

fprintf(stderr,"%s Copyright: YuHong(992126018601033)",PACKAGE_STRING);
fprintf(stderr,"bug report: %s\n\n",PACKAGE_BUGREPORT);

替换为:

fprintf(stderr,"CTorrent devel Copyright: YuHong(992126018601033)");
fprintf(stderr,"bug report: [email protected]\n\n");

开始使用

编译安装完毕会在/usr/local/bin/下创建程序ctorrent,下载种子最简单直接的命令就是

ctorrent 共产主义好.torrent

这个命令执行后会在当前目录开始下载种子共产主义好.torrent,但是下载完成以后如果不及时ctrlc停掉,就会一直上传,浪费流量!所以就要使用更高级的命令来控制它!

但是在此之前我们先来运行时的显示(以CTorrent为例)

10, [0/334/331], 6070,9845, | 5004,3984 E:3
10 - 连接人数(其他一些有你要下载文件的人)
0/334/331 - 已完成/全部/可利用的部分.
6070,9845 - 平均下载速度(in bytes/s), 平均上传速度(in bytes/s)
5004,3984 - 当前下载速度 (in bytes/s), 当前上传速度 (in bytes/s)
E:3 - 向他人请求文件被拒绝3次

现在运行ctorrent -h打开帮助,下面以加强版为例

Enhanced CTorrent dnh3.3.2   Original code Copyright: YuHong(992126018601033)
WARNING: THERE IS NO WARRANTY FOR CTorrent. USE AT YOUR OWN RISK!!!
General Options:
-h/-H           Show this message
-x              Decode metainfo (torrent) file only, don't download
-c              Check pieces only, don't download
-v              Verbose output (for debugging)
Download Options:
-e int          Exit while seed <int> hours later (default 72 hours)
-E num          Exit after seeding to <num> ratio (UL:DL)
-i ip           Listen for connections on specific IP address (default all/any)
-p port         Listen port (default 2706 -> 2106)
-I ip           Specify public/external IP address for peer connections
-u num or URL   Use an alternate announce (tracker) URL
-s filename     Download ("save as") to a different file or directory
-C cache_size   Cache size, unit MB (default 16MB)
-f              Force saved bitfield or seed mode (skip initial hash check)
-b filename     Specify bitfield save file (default is torrent+".bf")
-M max_peers    Max peers count (default 100)
-m min_peers    Min peers count (default 1)
-z slice_size   Download slice/block size, unit KB (default 16, max 128)
-n file_list    Specify file number(s) to download
-D rate         Max bandwidth down (unit KB/s)
-U rate         Max bandwidth up (unit KB/s)
-P peer_id      Set Peer ID prefix (default "-CD0303-")
-A user_agent   Set User-Agent header (default "Enhanced-CTorrent/dnh3.3.2")
-S host:port    Use CTCS server at host:port
-a              Preallocate files on disk
-T              Convert foreign filenames to printable text
-X command      Run command upon download completion ("user exit")
-d              Daemon mode (fork to background)
-dd             Daemon mode with I/O redirection
Make metainfo (torrent) file options:
-t              Create a new torrent file
-u URL          Tracker's URL
-l piece_len    Piece length (default 262144)
-s filename     Specify metainfo file name
-p              Private (disable peer exchange)
-c comment      Include a comment/description

首先,帮助文件分两部分,一部分是下载选项,一部分是制作选项。

选项 全称 说明
-e int 下载完毕后的做种时间(单位:小时),默认为72小时。
-p port 绑定端口,默认为2706。
-s save_as 重命名下载的文件,若是下载的是多个文件,则sava_as是包含多文件的目录。
-C cache_size 缓存大小,默认为16MB。
-f N/A 强制做种模式,不进行SHA1 HASH检查。
-b bf_filename piece位图文件名,详见BitField::SetReferFile()。
-M max_peers 客户端最多与多少个peer通信。
-m min_peers 客户端至少与多少个peer通信。
-n file_number 多文件下,选择哪个文件去下载(例如第二个文件file_number就为2)。
-D rate 限制最大下载速率(单位:KB/s)。
-U rate 限制最大上传速率(单位:KB/s)。
-P peer_id 客户端通信的ID,默认为-CD0102-。

下载数据文件示例:
ctorrent -s new_filename -e 12 -C 32 -p 6881 eg.torrent
制作种子文件示例:
ctorrent -t file_to_make.avi -s a.torrent -u protocol://address/announce

源码分析

有个牛人叫姚旭晨,他写了个[CTorrent程序源码分析],在此提供给大家,有兴趣的同学可以看一看[5]

相关推荐