Read more

Ruby: Downloading files from the Internet

Dominik Schöler
November 05, 2011Software engineer at makandra GmbH

This is easy:

require 'open-uri'

File.open('/target/path/to/downloaded.file', "wb") do |file|
  file.write open('http://example.com/your.file').read
end

Basic Authentication

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

When your file is protected by HTTP Basic Authentication, pass your credentials as hash:

File.open('/target/path/to/downloaded.file', "wb") do |file|
  file.write open('http://example.com/your.file', :http_basic_authentication => [your_username, your_password]).read
end
Posted by Dominik Schöler to makandra dev (2011-11-05 13:30)