There is a great number of possibilities to do this in Ruby (just to mention a few: standard net/http, curb, mechanize, rio etc.). I have chosen a semi-standard way (=no need to learn new syntax, but definitely simpler than net/http): open-uri.
require 'open-uri'
open('target.file','w') {|f| f.write open("my.url.com/source.file", :http_basic_authentication=>['ueser', 'pass']) }
I am using Ruby for more than 2 years already but it’s succinctness still keeps me amazed!
Pingback: [Ruby] é€éŽ http-basic-auth 下載檔案 « Reading for Life
I wrote something similar for republishing feeds behind http basic authentication just a few months ago:
http://php.vanhecke.info/2008/01/20/republish-a-feed-or-other-data-protected-by-http-basic-authentication/
(using the PHP snoopy class).
Indeed a lot more verbose than ruby 🙂