How to Wget a File From a Password-Protected Website

| | 1 min read

Wget is a command-line utility that helps download files from the web. It’s a non-interactive program that works in the background. We can use the wget commands as part of the cronjobs as well to do routine tasks.

For example, if we want to download a sample.php file from a website ‘mywebsite.com”, we could use the command below to download the file

wget http://mywebsite.com/sample.php

But suppose if the website you want to download is password protected, the normal wget commands won’t work as it will show an access denied error while trying to download. But we could use the option below to add the username and password of the password-protected website alongside the wget commands to fetch the file. An example is as below

wget --user USER --password PASS https://mywebsite.com/sample.php

Replace the ‘USER’ with the username and PASS with the password of the password-protected website to download the file