From: Edwin Fine Date: 2006-12-24T00:22:56+09:00 Subject: Re: Question: Downloading files with open(-uri)? William James wrote: > Mariano Kamp wrote: >> I tested it with an URL that returns plain html and that worked >> http://downloads.scribemedia.net/rails2006/06_railsCorePanel_full.m4v >> print "." >> Mariano > There's nothing wrong with your program; I tested it by > downloading a picture. If you have a dial-up connection, maybe > the transfer is progressing very slowly. Actually, I think the site is slow or overloaded. The movies are 250MB - 500MB in size, and the download speed I am getting is around 52 KBytes/second (and I have a broadband connection). This code works better at showing progress: require 'open-uri' urls = %w{ http://ibm.com http://downloads.scribemedia.net/rails2006/03_martin_fowler_full.m4v http://downloads.scribemedia.net/rails2006/02_dave_thomas_full.m4v http://downloads.scribemedia.net/rails2006/01_dh_hansson.m4v http://downloads.scribemedia.net/rails2006/04_paul_graham_full.m4v http://downloads.scribemedia.net/rails2006/06_railsCorePanel_full.m4v http://downloads.scribemedia.net/rails2006/07_why_lucky_stiff.m4v } BUFFER_SIZE = 8 * 1_024 urls.each do |url| puts "downloading #{url}" out_file = url.split(/\//).last puts "Writing to #{out_file}" open(url, "r", :content_length_proc => lambda {|content_length| puts "Content length: #{content_length} bytes" }, :progress_proc => lambda { |size| printf("Read %010d bytes\r", size.to_i) }) do |input| open(out_file, "wb") do |output| while (buffer = input.read(BUFFER_SIZE)) output.write(buffer) end end end puts "\ndone." end puts "All downloads done." -- Posted via http://www.ruby-forum.com/.