How do I force wget to use a proxy server without modifying system files? [duplicate]

I'd like to know an equivalent to wget enabling me to set the proxy while calling the command (like wget --proxy=$http_proxy).

Any ideas ?


Solution 1:

The -e option allows you to provide commands as in wgetrc at the command line so you do not need to change a file ...

wget -e use_proxy=yes -e http_proxy=$proxy http://askubuntu.com

Solution 2:

Without modifying your system files at /etc/wgetrc you could create a file at your home directory ~/.wgetrc. It will enable you to modify wget settings locally at user level. Now write the following at ~/.wgetrc to use wget behind a proxy server:

use_proxy = on
http_proxy =  http://username:[email protected]:port/
https_proxy =  http://username:[email protected]:port/
ftp_proxy =  http://username:[email protected]:port/

If you do not have proxy username and password just write the proxy-address and port everywhere like,

http_proxy =  http://proxy.server.address:port/

This should work. I am assuming you already have proxy settings for all other applications.

Solution 3:

You need to edit the wgetrc file located at /etc/wgetrc.

Use your favourite text editor, ie: nano /etc/wgetrc to edit it

Look for the http_proxy tag and remove the # in front of it, add the proxy server after the = sign, ie:

http_proxy=http://foo.proxy:8080

Then search for the use_proxy tag and remove the # in front of it, save the file.

wget will be then using the specified proxy server.

If you can't change system configuration with your user you can copy the current configuration to a place you can edit it, ie: cp /etc/wgetrc ~ and use the --config=~/wgetrc option to force wget to use the configuration you altered instead of the global configuration.