DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
How To Download Files With Ruby
// Note: the "b" in "wb" in the open method may not be needed in
// non-Windows environments. In Windows it indicates that you're writing
// binary information. You probably won't need it for downloading straight text
// or html either.
require 'net/http'
Net::HTTP.start("static.flickr.com") { |http|
resp = http.get("/92/218926700_ecedc5fef7_o.jpg")
open("fun.jpg", "wb") { |file|
file.write(resp.body)
}
}
puts "Yay!!"






Comments
Snippets Manager replied on Sat, 2009/05/09 - 2:35am
Snippets Manager replied on Tue, 2011/07/19 - 4:28am
require 'rubygems' require 'image_downloader' downloader = ImageDownloader::Process.new('www.test.com','img_dir/') downloader.parse(:any_looks_like_image => true) downloader.download()Snippets Manager replied on Sat, 2009/05/09 - 2:35am
def download full_url, to_here require 'open-uri' writeOut = open(to_here, "wb") writeOut.write(open(full_url).read) writeOut.close endTerry Donaghe replied on Fri, 2006/08/25 - 3:42pm