How to use a proxy with wget
In short: GNU wget works with an HTTP proxy only. Pass it with -e use_proxy=yes -e https_proxy=http://HOST:PORT and add –proxy-user and –proxy-password, or set http_proxy and https_proxy in the shell or in .wgetrc. wget does not speak SOCKS5, so use curl or an HTTP order for that.
wget downloads files and pages from the shell. It reads the proxy from settings, not from a single flag, so the setup differs a little from curl. The values come from one row in My Proxies in your dashboard; the protocol on the row must be HTTP.
On the command line
wget -e use_proxy=yes -e http_proxy=http://HOST:PORT -e https_proxy=http://HOST:PORT \
--proxy-user=LOGIN --proxy-password=PASSWORD https://example.com/file.txt
-e runs a .wgetrc command for this one call. The proxy address keeps http://, also
for HTTPS pages: it names how wget talks to the proxy. --proxy-user and
--proxy-password hold the login, so the password needs no encoding there.
With environment variables
export http_proxy="http://LOGIN:PASSWORD@HOST:PORT"
export https_proxy="http://LOGIN:PASSWORD@HOST:PORT"
export no_proxy="localhost,127.0.0.1"
Special characters in the password must now be percent-encoded: @ is %40, : is
%3A, / is %2F, # is %23 and % is %25. Unset the variables with
unset http_proxy https_proxy to go direct again.
With .wgetrc
Add these lines to ~/.wgetrc:
use_proxy = on
http_proxy = http://HOST:PORT
https_proxy = http://HOST:PORT
proxy_user = LOGIN
proxy_password = PASSWORD
Every wget run then uses the proxy until you delete the lines. Restrict the file to yourself, because it holds the password in plain text.
No SOCKS5
GNU wget has no SOCKS5 proxy support. If the order uses SOCKS5, either switch it to HTTP
with Change protocol and copy the details again, or use
curl with socks5h://. The
SOCKS5 proxies page covers the protocol.
Which method to pick
The command line suits a single download and leaves nothing behind. Environment variables
suit a shell session in which several tools should share one proxy, since curl and Git
read the same names. .wgetrc suits a machine where every wget run should use the proxy
and you want no repeated typing. Choose the narrowest one that does the job, so a forgotten
setting does not keep routing traffic later.
Check it
Run wget -qO- https://example.com and compare, or download one page of
What Is My IP through the proxy and read the address in it. An error
407 Proxy Authentication Required means the proxy rejected the login:
proxy error 407 lists what to check. Plan and pricing are on the
ISP proxies page.
