你知道有哪些Python库可以通过Bittorent发送/接收文件吗?
我有一些很大的文件需要传输到很多服务器上。目前我们使用rsync这个工具,但我想试试bittorent。
我正在研究Deluge这个用Python写的bittorent客户端,但它用到了twisted,实在是太复杂了。你知道有没有简单一点的方案吗?
补充一下:我刚看到Facebook用Bittorent来部署代码。也许他们为此发布了自己的库,但我找不到。你听说过吗?
2 个回答
2
最初的BitTorrent客户端是用Python语言写的。你有没有去看看这个呢?
5
我强烈推荐 libtorrent-rasterbar。这是一个用C++写的库,还可以和Python一起使用。它是支持Deluge、Transmission、Miro等很多BitTorrent客户端的基础库。
跟另一个libtorrent(那个属于rTorrent项目的)相比,这个库正在积极更新,支持所有现代的协议扩展,比如DHT、元数据传输,甚至还有一些专有的uTorrent扩展,比如对等交换(PEX)。
这个库的使用说明非常详细。
从下面这个完全可用的简单客户端示例中可以看出,你不需要了解底层协议的每一个细节(当然,了解这些会有很大帮助):
#!/bin/python
# Copyright Arvid Norberg 2008. Use, modification and distribution is
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import libtorrent as lt
import time
import sys
ses = lt.session()
ses.listen_on(6881, 6891)
info = lt.torrent_info(sys.argv[1])
h = ses.add_torrent({'ti': info, 'save_path': './'})
print 'starting', h.name()
while (not h.is_seed()):
s = h.status()
state_str = ['queued', 'checking', 'downloading metadata', 'downloading', \
'finished', 'seeding', 'allocating', 'checking fastresume']
print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
s.num_peers, state_str[s.state]),
sys.stdout.flush()
time.sleep(1)
print h.name(), 'complete'
顺便说一下,Facebook有一个专门的页面介绍他们的开源项目,地址是 http://developers.facebook.com/opensource/。不过上面没有列出任何BitTorrent的实现。