為wget命令設定代理

FrankYou發表於2017-04-11

實驗環境:ubuntu 12.04 LTS  goagent

方法一、在環境變數中設定代理

export http_proxy=http://127.0.0.1:8087

方法二、使用配置檔案

為wget使用代理,可以直接修改/etc/wgetrc,也可以在主資料夾下新建.wgetrc,並編輯相應內容,本文采用後者。

將/etc/wgetrc中與proxy有關的幾行復制到~/.wgetrc,並做如下修改:

複製程式碼
#You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://127.0.0.1:8087/
http_proxy = http://127.0.0.1:8087/
ftp_proxy = http://127.0.0.1:8087/

# If you do not want to use proxy at all, set this to off.
use_proxy = on
複製程式碼

 這裡 use_proxy = on 開啟了代理,如果不想使用代理,每次都修改此檔案未免麻煩,我們可以在命令中使用-Y引數來臨時設定:

-Y, --proxy=on/off           開啟或關閉代理

方法三、使用-e引數

wget本身沒有專門設定代理的命令列引數,但是有一個"-e"引數,可以在命令列上指定一個原本出現在".wgetrc"中的設定。於是可以變相在命令列上指定代理:

-e, --execute=COMMAND   執行`.wgetrc'格式的命令

例如:

wget -c -r -np -k -L -p -e "http_proxy=http://127.0.0.1:8087" http://www.subversion.org.cn/svnbook/1.4/

 這種方式對於使用一個臨時代理尤為方便。

注: 如果是https,則引數為:-e "https_proxy=http://127.0.0.1:8087"

 

使用https時如果想要忽略伺服器端證書的校驗,可以使用 -k 引數。

 

相關文章