32

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 ?

Jesse Nickles
  • 462
  • 4
  • 12
merours
  • 425

5 Answers5

61

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
muru
  • 207,228
jhs
  • 611
36

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:password@proxy.server.address:port/
https_proxy =  http://username:password@proxy.server.address:port/
ftp_proxy =  http://username:password@proxy.server.address: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.

Braiam
  • 69,112
sourav c.
  • 46,120
3

From the command line only I've found success preceding the wget command with the http_proxy information without the need of using the environment variables. For example:

  • $ http_proxy=<proxy-server-ip>:<port> wget http://www.example.com/
  • $ https_proxy=<proxy-server-ip>:<port> wget https://www.example.com/
Lebecca
  • 103
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.

Bruno Pereira
  • 74,715
2

Option that is not mentioned, but should be mentioned: Use environmental variables (depending your distro):

http_proxy=http://<proxy-server-ip>:<port>
export http_proxy

or simply

export http_proxy=http://<proxy-server-ip>:<port>

Same for:

https_proxy=http://<proxy-server-ip>:<port>
ftp_proxy=http://<proxy-server-ip>:<port>

You can include a username and password, if you have special characters in your password be sure to include the '-s.

http_proxy='http://<username>:<password>@<proxy-server-ip>:<port>'

Examples:

export http_proxy=http://172.16.1.100:8080
export https_proxy='http://johndoe:ABC!123@172.16.1.100:8080'
muru
  • 207,228
gjs
  • 21
  • 2