Reputation: 25672
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.
Upvotes: 1
Views: 266
Reputation: 1300
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
Upvotes: 2
Reputation: 5620
I think it expects a filename. Could it be as simple as needing to require 'open-uri'
?
Upvotes: -1