RubyTorrent 问题

发布于 2024-07-24 23:30:50 字数 596 浏览 8 评论 0原文

我正在尝试创建一个脚本来帮助我在 Windows 内部网络上移动大型文件,并希望 Ruby 与 BitTorrent 结合起来会是理想的选择。 然而,我的代码似乎并没有真正下载任何东西。

我知道 RubyTorrent 项目已经被废弃很长时间了,所以我希望我的一位 Stackoverflow 用户能够帮助我。

我的代码(到目前为止):

require 'rubytorrent'
bt = RubyTorrent::BitTorrent.new('http://www.mininova.org/get/2511754')
puts bt.tracker
puts bt.port
thread = Thread.new do
  while true
    puts bt.percent_completed
    sleep 15
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join

如您所见,“bt.tracker”行显示为零,因此传递 .torrent 文件可能会出现问题,但为什么它会传递文件的其余部分? ?

任何帮助使其发挥作用的帮助将不胜感激。

I am trying to create a script to help me move large files accross an internal Windows network, and was hoping that Ruby, in conjunction with BitTorrent would be ideal. However, my code doesnt seem to actually download anything.

I know the RubyTorrent project has been abandoned for a long time, so I was hoping one of my fellow Stackoverflow'ers could help me.

My code (so far is):

require 'rubytorrent'
bt = RubyTorrent::BitTorrent.new('http://www.mininova.org/get/2511754')
puts bt.tracker
puts bt.port
thread = Thread.new do
  while true
    puts bt.percent_completed
    sleep 15
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join

As you can see, the 'bt.tracker' line is coming up as nil, so it might be a problem passing the .torrent file, but then why does it pass the rest of the file ok?

Any help getting this to work would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的他你的她 2024-07-31 23:30:50

您的代码很好,唯一的问题是当您仍未连接到跟踪器时尝试打印 bt.tracker 。
如果连接后尝试打印,没有问题

begin
  bt = RubyTorrent::BitTorrent.new('yourtorrent')
rescue IOError
  puts "Can't open the torrent"
end

bt.on_event(self, :tracker_connected) { |s, url| puts "[tracker] connected to tracker #{url}" }

puts 'Tracker : '+bt.tracker.to_s
puts bt.port
thread = Thread.new do
  while true
    puts 'Tracker : '+bt.tracker.to_s
    puts bt.percent_completed
    sleep 10
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join

Your code is good, the only problem is that you try to print bt.tracker when you're still not connected to the tracker.
If you try to print it after being connected there's no problem

begin
  bt = RubyTorrent::BitTorrent.new('yourtorrent')
rescue IOError
  puts "Can't open the torrent"
end

bt.on_event(self, :tracker_connected) { |s, url| puts "[tracker] connected to tracker #{url}" }

puts 'Tracker : '+bt.tracker.to_s
puts bt.port
thread = Thread.new do
  while true
    puts 'Tracker : '+bt.tracker.to_s
    puts bt.percent_completed
    sleep 10
  end
end
bt.on_event(self, :complete) { thread.kill }
thread.join
伪装你 2024-07-31 23:30:50

我认为它需要一个文件名。 难道就像需要 require 'open-uri' 一样简单吗?

I think it expects a filename. Could it be as simple as needing to require 'open-uri' ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文