Username and password with wget/curl

 

To download a url with basic authentication we need to pass username & password.

To acheive this functionality with wget or curl observer following examples:

With curl:

$ curl -u 'username:password' 'http://www.example.com'

With wget:

$ wget --user='username' --password='password' 'http://www.example.com'

Wget with cookie:

Login to server & save cookie to a file:
$ wget --save-cookies cookiesFile.txt --post-data 'user=username&password=password' http://www.example.com/login.html

Download a page by using saved cookie file:
$ wget --load-cookies cookiesFile.txt -p http://www.example.com/somecontent.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s