How to Use Wget Behind a Proxy

in #proxy2 months ago

Whether you’re scraping a website, downloading huge datasets, or just automating repetitive file transfers, Wget makes it effortless. And throw a proxy into the mix, and suddenly you’re navigating complex networks like a pro.
Command-line downloads aren’t just for geeks—they’re for anyone who wants speed, control, and reliability without waiting on a GUI. This guide walks you through installing Wget, running downloads, and using advanced proxy configurations to get the job done safely and efficiently.

What Does Wget Do

Wget is a free, open-source command-line tool that fetches files from the web. Simple name, powerful functionality: “World Wide Web” + “get.”
It works on Linux, macOS, and Windows. HTTP, HTTPS, FTP—Wget handles them all. Think of it as a silent, automated downloader that works while you focus on more interesting problems.

Installing Wget

Linux

Most distributions already have Wget. Check with:

wget --version

Missing? Install it easily:

Debian/Ubuntu:

sudo apt update andand sudo apt install wget

Fedora/CentOS/RHEL:

sudo dnf install wget

Ensure it’s in your PATH. Usually, your package manager takes care of this.

macOS

Not bundled by default, but Homebrew makes it simple:

xcode-select --install
brew install wget
wget --help

Windows

Download the precompiled wget.exe from the GNU site, put it in a PATH folder like C:\Windows\System32, and test:

wget --help

Wget Fundamentals

Command Syntax

wget [options] [URL]

Straightforward, flexible, and infinitely scriptable.

Single File Download

wget https://example.com/sample-file.zip

Rename on the fly:

wget -O myfile.zip https://example.com/download/latest.zip

Multiple Files

Directly:

wget URL1 URL2 URL3

Or from a text file for dozens of URLs:

wget -i urls.txt

Custom User-Agent

Avoid blocks by spoofing your user-agent:

wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com/

For frequent use, add a default to .wgetrc.

Limit Download Speed

Avoid hogging bandwidth:

wget --limit-rate=200k https://example.com/large-file.iso

Extract Links Without Downloading

wget --spider --force-html -r -l1 https://example.com 2>and1 | grep -o 'http[^ ]*'

Spider mode scans pages without downloading. Perfect for building quick link lists.

Setting Up Proxies with Wget

Proxies add flexibility, privacy, and bypass network restrictions. Wget handles them via environment variables, config files, or command-line options.

Set a Proxy

Environment Variables:

export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"

Config File (~/.wgetrc):

http_proxy = http://proxy.example.com:8080
https_proxy = http://proxy.example.com:8080

Command-Line Override:

wget -e use_proxy=yes -e http_proxy=http://proxy.example.com:8080 http://example.com/file.pdf

Use the method that fits your workflow—occasional overrides or persistent setup.

Proxy Authentication

Some corporate or paid proxies require credentials. Without them, Wget throws:

407 Proxy Authentication Required

Fix it:

export http_proxy="http://username:password@proxy.example.com:8080"
wget --proxy-user=username --proxy-password=password http://example.com/file.pdf

Wget only supports Basic HTTP authentication. If your proxy uses NTLM, Kerberos, or similar, consider cURL.

SOCKS and Rotating Proxies

SOCKS: Wget doesn’t natively support it. Use proxychains or switch to cURL.
Rotating IPs: Ideal for scraping or repeated requests. Premium proxy providers make this easy—plug in credentials, and Wget rotates automatically, avoiding blocks.

Solving Common Proxy Errors

407 Proxy Authentication Required: Check credentials and authentication type.
400 Bad Request: Usually a misconfigured proxy URL, port, or mismatched protocol (HTTP vs HTTPS).

Wget and cURL Compared

Recursive downloads: Wget shines—mirror entire sites effortlessly.
API and uploads: cURL excels—POST, PUT, multi-method requests.
Proxy handling: cURL supports SOCKS5 and advanced auth; Wget sticks to HTTP/HTTPS.

Conclusion

Proxies no longer have to be obstacles. When combined with proper proxy configuration, Wget becomes a powerful tool for automated downloads, web scraping, and flexible network navigation. Whether downloading a single file or mirroring entire websites, it is reliable, efficient, and highly capable when the situation demands.