I need to download movie files from a website that requires logging in. I started prototyping a script using Mechanize, but I'm wondering if Curl supports sending username and password to the server, which would make my work a lot faster.
A:
If it's HTTP Basic authentication, you can use the -u switch... if memory serves...
curl ... -u username:password ...
If it's not HTTP basic, you'll probably need to look at the requests and responses to see what's being passed around, and it may not be feasible to automate the process. In addition, if there's more elaborate login configuration like that, the terms and conditions of the site might prevent you from doing what you want to do, so might be worth checking.
Brabster
2010-09-29 16:58:46
+1
A:
I would use httparty rather than curl. It supports authentication.(http://httparty.rubyforge.org)
sudo gem install httparty
Here is an example that shows authentication taken from the site.
class Twitter
include HTTParty
base_uri 'twitter.com'
basic_auth 'username', 'password'
end
Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})
abdollar
2010-09-29 17:24:42
Unfortunately HTTParty doesn't support files. :( http://groups.google.com/group/httparty-gem/browse_thread/thread/fe8a3af8c46e7c75
picardo
2010-09-29 21:02:35
I discovered that I can still download stuff with HTTParty using File.open( "/tmp/my_movie.mov", "w") do |movie| movie << HTTParty.get( "http://example.com/movie.mov" )end
picardo
2010-09-30 16:10:57