views:

34

answers:

2

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
+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
Unfortunately HTTParty doesn't support files. :( http://groups.google.com/group/httparty-gem/browse_thread/thread/fe8a3af8c46e7c75
picardo
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