Using wget to download a file from a password prot

2019-03-30 12:17发布

问题:

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?

回答1:

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.