使用用户名和密码的HTTPS的正确wget命令语法是什么?

Eme*_*ngo 33 wget

我想使用wget使用此URL远程下载文件:

https://test.mydomain.com/files/myfile.zip
Run Code Online (Sandbox Code Playgroud)

网站test.mydomain.com需要登录.我想使用此命令在我的另一台服务器上下载该文件,但它不起作用(不完全下载文件):

wget --user=myusername --password=mypassword https://test.mydomain.com/files/myfile.zip
Run Code Online (Sandbox Code Playgroud)

如果我的用户名是myusername,密码是mypassword,那么正确的wget语法是什么?

以下是我输入上述命令后的返回消息:

Resolving test.mydomain.com (test.mydomain.com)... 123.456.789
Connecting to test.mydomain.com (test.mydomain.com)|123.456.789|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://test.mydomain.com/login/unauthorized [following]
--2013-01-30 02:01:32--  https://test.mydomain.com/login/unauthorized
Reusing existing connection to test.mydomain.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://test.mydomain.com/login [following]
--2013-01-30 02:01:32--  https://test.mydomain.com/login
Reusing existing connection to test.mydomain.com:443.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `myfile.zip'
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?请帮忙.谢谢.

tho*_*buj 62

通过指定选项--user和--ask-password,wget将要求提供凭据.以下是一个例子.根据您的需要更改用户名和下载链接.

wget --user=username --ask-password https://xyz.com/changelog-6.40.txt
Run Code Online (Sandbox Code Playgroud)

  • +1使用`--ask-password`而不是以明文形式提供它以便在shell历史中看到. (15认同)
  • 如果你在脚本中使用wget --ask-password是没用的 (9认同)

Dav*_*gal 18

我发现wget没有对某些服务器进行适当的身份验证,可能是因为它只符合HTTP 1.0.在这种情况下,curl(符合HTTP 1.1)通常可以解决问题:

curl -o <filename-to-save-as> -u <username>:<password> <url>


niC*_*Mel 8

这不是您的文件已部分下载.它无法通过身份验证,因此下载例如"index.html",但它将其命名为myfile.zip(因为这是您要下载的内容).

我按照@thomasbabuj建议的链接,最终想出来了.

您应该尝试添加--auth-no-challenge,并且@thomasbabuj建议替换您的密码条目

wget --auth-no-challenge --user=myusername --ask-password https://test.mydomain.com/files/myfile.zip
Run Code Online (Sandbox Code Playgroud)