Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wget to download a file from a password protected link

I am trying to use wget to download a file from a http link that is password protected. I am using the following syntax:

wget --http-user=user --http-password=xxxxxx http://......

Am I using the right syntax? Should user and password be surrounded by quotes or double quotes?

like image 826
user3656863 Avatar asked May 20 '14 13:05

user3656863


1 Answers

I did this a few years ago and luckily found the script in a backup I still have.

I remember it was a two-stage process.

The first step is to get and store the cookie(s):

wget --keep-session-cookies --save-cookies nameofcookiesfile.txt --post-data 'email=my.email@address.com&password=mypassword123' https://web.site.com/redirectLogin -O login.html

The second is to use those cookies to get the file/page you need:

wget --load-cookies nameofcookiesfile.txt -p http://web.site.com/section/ -O savedoutputfile.html -nv

These are the commands exactly as I used them (except I have changed usernames, passwords, filenames and websites). I also came across this link which may be of some assistance particularly the "referer" part:

http://www.linuxscrew.com/2012/03/20/wget-cookies/

Hope this helps or at least gives someone a starting point.

like image 74
Craig Avatar answered Sep 22 '22 14:09

Craig