I need to download a file from a website which has a URL formatted like:

http://www.server.com/downloads/1234/

This redirects to a .zip file which has to be saved. There is also a need to authenticate based on username and password.

I tried to use wget, curl and lynx with no luck.

UPDATE:

  • wget doesnt work with redirection. It simply downloads the webpage instead of the zip file.
  • curl gives the error "Maximum redirection exceeded > 50 "
  • lynx also gives the same error.
link|improve this question
1  
Are you getting errors or is it simply not working? – Jordan Aug 9 '11 at 5:18
2  
How did you invoke lynx/curl/wget? What error did you get? – Noufal Ibrahim Aug 9 '11 at 5:19
I have updated the question.. – Vicky Aug 9 '11 at 5:44
1  
If you have to log in and then the site redirects then you'll have to authenticate (submit your user/pass), probably a POST, then use the cookie the is returned in the next request. The curl error you're getting is probably you missing a parameter or cookie in the redirection (e.g. they set a Session cookie and you're not passing it on the redirection so it redirect you away, then redirect you back...infinite loop perhaps???). – Yzmir Ramirez Aug 9 '11 at 5:49
feedback

migrated from stackoverflow.com Aug 9 '11 at 6:17

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 3 down vote accepted

Wget does support redirect, does this work?

wget --user=USER --password=PASS --max-redirect URL

Note that if the site does not implement HTTP Authentication (require a form submission via GET or POST), then you'll need to setup some more work (given the little information you give about the site where the file is, a good answer is hard to give)

wget --post-file=datafile --keep-session-cookies --max-redirect URL

and your datafile could look like

username=USER
password=PASS

where username and password should be the name of the form fields being submitted.

NOTE : the site needs to redirect to the actual Zip file and not some other page where there is a link to the Zip file. If this is the case, you'll need to write a parsing script because neither Curl or Wget will help you there. They are tools to get content off of a given Url, they are not meant to "guess" you want you want them to fetch; they simply download what the server sends.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.