4

I'm trying to download a file from a website that requires login. This command retrieves the cookie.txt and the downloaded html shows I'm logged in (ok):

(I broke the command in lines for readability)

wget 
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) 
Gecko/20100101 Firefox/45.0" 
--keep-session-cookies
--save-cookies cookies.txt
--post-data "login_username=MyUserName&login_password=*******" 
--header="Host: somewebsite.com"
--header="Referer: http://somewebsite.com/files/download.php?i=2157716" 
http://somewebsite.com/login.php

Here I get cookies.txt. (all ok). And after that: (trying to download)

wget 
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) 
Gecko/20100101 Firefox/45.0" 
--load-cookies cookies.txt
--header="Host: somewebsite.com"
--header="Referer: http://somewebsite.com/files/download.php?i=2157716" 
--header="Connection: keep-alive" --header="Accept-Language: en-US,en;q=0.5"
--header="Accept-Encoding: gzip, deflate"
http://somewebsite.com/files/dl.php?t=2157716

But instead of downloading the file it returns an HTML saying that the file can only be downloaded from the website.

Here is the POST data from Firefox right before the download starts:

post data from actual Firefox download

What is missing?

  • Could be that the url you think is the download isn't. For example, wget doesn't handle javascript redirects. – Ouroborus Apr 5 '16 at 1:09
1

Solved. The HTML has a hidden form that sends the request via POST. I just had to add --post-data "login_username=****&login_password=****". The server only starts the download if it is POST request.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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