Basic WGET Command to Login and Download File
filed in Linux on Jul.24, 2009
GNU Wget – free utility for non-interactive download of files from the Web.
suppossed you’re a member of some site [ex: http://www.doesnt-exist.com]. you want to download some file from there. but first, you need to login. the question is, how to download file from site that ask user to login first, using wget? i’ll show you how.
first, we need to get cookies from the site, then save it to file [ex: cookies.txt]. we simulate the login process using wget.
wget --keep-session-cookies --save-cookies cookies.txt --post-data 'username=foo&password=bar' http://www.doesnt-exist.com/login/index.php
after we got the cookies file, the next step is, we start to download file. don’t forget to load the cookies that we’ve saved before.
wget --load-cookies cookies.txt -p http://www.doesnt-exist.com/some_directory/the_other_directory/some_file.ext -t 0 -c
Hints:
- you need to know the login url. in this example i’m using [http://www.doesnt-exist.com/login/index.php]
- you need to know the variable (text field) name for username and password. you can find it by ‘view source‘ the login page.
- you need to know exactly the file’s url that you want to download.
good luck. hope it helps.

