Friday, April 5, 2019

How to use wget to download file via proxy in linux?

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:


  1. ~/.wgetrc: User startup file.
  2. /etc/wgetrc: Default location of the global startup file.
  3. Set proxy variables in shell for current pseudo-terminal.
  4. ~/.bash_profile: User specific environment.
  5. /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]

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]

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]

4. Direct command line
$wget -e use_proxy=yes -e http_proxy=http://[Proxy_Server]:[port]  URL

No comments:

Post a Comment