在Linux命令行上使用Wget下载文件

时间:2019-05-19 01:25:55  来源:igfitidea点击:

wget是Linux命令行实用程序。
wget广泛用于从Linux命令行下载文件。
有许多选项可以从远程服务器下载文件。
wget工作相同的打开url在浏览器窗口。

1:使用Wget下载文件

下面的示例将从服务器下载文件到当前本地目录。

$ wget https://theitroad.com/file.zip

2:下载文件并保存到特定位置

下面的命令将在/opt文件夹下载zip文件,文件名为file.zip。
-O用于指定目标文件夹

# wget https://theitroad.com/file.zip -O /opt/file.zip

3:从FTP下载文件

有时我们需要从ftp服务器下载文件,所以wget可以轻松地从ftp url下载文件,如下所示。

# wget ftp://ftp.theitroad.com/file.zip

4:从密码保护的url下载文件

有时我们需要指定用户名和密码来下载文件。
虽然使用浏览器很容易,但使用命令行,它不会登录凭据。
下面的例子将展示如何使用用户名,密码,同时下载文件从密码保护的来源。
4.1:从密码保护的ftp服务器下载文件。

$ wget --ftp-user=username --ftp-password=secretpassword ftp://ftp.theitroad.com/file.zip

或者

$ wget ftp://username:Hyman@theitroad/file.zip

4.2:从密码保护的http服务器下载文件。

# wget --http-user=username --http-password=secretpassword https://theitroad.com/file.zip
或者

# wget --user=username --password=secretpassword https://theitroad.com/file.zip

4.3:下载文件后,密码保护代理服务器。

$ wget --proxy-user=username --proxy-password=secretpassword https://theitroad.com/file.zip

5:从不可信的安全URL下载文件。

如果下载url使用不受信任的ssl证书,wget将不会下载该文件。
但是我们可以在url中使用-no-check-certificate参数下载。

$ wget  https://theitroad.com/file.zip  --no-check-certificate