Using wget to download a file from a password protected link Using wget to download a file from a password protected link unix unix

Using wget to download a file from a password protected link


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.