Yin Chaoyi
2/15/2006 10:31:00 AM
Hello,
I am a ruby newbie. When I use the attached script, the file downloaded
over a slow link is always incomplete. I can successfully download a
much larger file over a fast link.
I use ethereal to capture the communication. It's the client which
initials the disconnection by first sending a FIN then followed by
several RSTs.
Any ideas? Thanks for helping!
------
#!/usr/bin/env ruby
require 'http-access2'
def fetch(url, filename)
proxy = ENV['HTTP_PROXY']
clnt = HTTPAccess2::Client.new(proxy)
begin
target = url
clnt.reset(target)
result = clnt.get(target)
rescue SystemCallError
return "Connection Error"
end
if result.contenttype != "application/pdf"
return "can't get pdf!"
else
f = File.new(filename, File::CREAT|File::RDWR|File::TRUNC, 0644)
f.puts result.content
f.close
end
"Success"
end
puts fetch(ARGV.shift, ARGV.shift)