How to use wget to download file via proxy

The wget program allows you to download files from URLs. Although it can do a lot, the simplest form of the command is: wget [some URL]. Assuming no errors, it will place that file in the current directory. If you do not specify a filename, by default it will attempt to get the index.html file.

This document descript how to set wget (The non-interactive network downloader) to download file via proxy.

wget Configuration files

Below are wget configuration files listed by their priorities:

  • ~/.wgetrc: User startup file.
  • /etc/wgetrc: Default location of the global startup file.
  • Set proxy variables in shell for current pseudo-terminal.
  • ~/.bash_profile: User specific environment.
  • /etc/profile: System wide environment.
Note: If higher priority configuration is not set, then the very next priority configuration takes effective. For instance, ~/.wgetrc was not configured with proxy settings but /etc/wgetrc was configured, then proxy settings in /etc/wgetrc are the working proxys in wget.

Configuring wget proxy

1. Add below line(s) in file ~/.wgetrc or /etc/wgetrc:

http_proxy = http://[Proxy_Server]:[port]
https_proxy = http://[Proxy_Server]:[port]
ftp_proxy = http://[Proxy_Server]:[port]

2. Set proxy variable(s) in a shell manually:

$ export http_proxy=http://[Proxy_Server]:[port]
$ export https_proxy=$http_proxy
$ export ftp_proxy=$http_proxy

Verify the variable values using the “env” command.

$ env | grep proxy
http_proxy=http://[Proxy_Server]:[port]
https_proxy=http://[Proxy_Server]:[port]
ftp_proxy=http://[Proxy_Server]:[port]

3. Add below line(s) in file ~/.bash_profile or /etc/profile:

# export http_proxy=http://[Proxy_Server]:[port]
# export https_proxy=http://[Proxy_Server]:[port]
# export ftp_proxy=http://[Proxy_Server]:[port]
Related Post