如何在 Linux 上為 wget 設定代理?


Wget 是一個 Linux 命令列實用程式,用於從全球資訊網 (WWW) 檢索檔案,並使用 HTTPS 和 FTP 等協議。它是一個免費提供的軟體包,可以下載並安裝在任何支援 Linux 的架構上。

wget 的關鍵特性之一是能夠在網路出現問題時自動從中斷的地方繼續下載。還應該注意的是,它會遞迴刪除檔案,並且會一直嘗試下載所有檔案,直到完全檢索到為止。

安裝 wget

適用於 Ubuntu/Fedora

sudo apt-get install wget

適用於 Mac OS X

yum install wget

現在我們瞭解了 wget,讓我們首先探索一個示例,其中我們將嘗試使用 wget 命令從 url 下載檔案。

示例

wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz

輸出

immukul@192 linux-code % wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
--2021-07-11 12:12:20-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 446966 (436K) [application/x-gzip]
Saving to: 'wget-1.5.3.tar.gz'

wget-1.5.3.tar.gz
100%[========================================================>]
436.49K 285KB/s in 1.5s

2021-07-11 12:12:23 (285 KB/s) - 'wget-1.5.3.tar.gz' saved [446966/446966]

現在,如果我們想在 wget 命令中使用代理,可以使用下面提到的兩種方法之一。

方法 1

命令

wget -e use_proxy=yes -e http_proxy=localhost:8080 ...

方法 2

命令

use_proxy=yes

http_proxy=localhost:8080

https_proxy=localhost:8080

以上兩種方法都允許您使用代理執行 wget

更新於: 2021-07-30

661 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告