【问题标题】:What is the correct wget command syntax for HTTPS with username and password?带有用户名和密码的 HTTPS 的正确 wget 命令语法是什么?
【发布时间】:2013-01-30 02:12:05
【问题描述】:

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

https://test.mydomain.com/files/myfile.zip

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

wget --user=myusername --password=mypassword https://test.mydomain.com/files/myfile.zip

如果我的用户名是 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'

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

【问题讨论】:

标签: wget


【解决方案1】:

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

wget --user=username --ask-password https://xyz.com/changelog-6.40.txt

【讨论】:

  • +1 用于使用 --ask-password 而不是以纯文本形式提供它以便在 shell 历史记录中看到。
  • 如果你在脚本中使用 wget --ask-password 没用
  • 谢谢 我如何在linux上安全地存储密码,这个wget是否自动验证,无需输入用户名和密码?
【解决方案2】:

我发现 wget 不能正确地通过某些服务器进行身份验证,可能是因为它仅符合 HTTP 1.0。在这种情况下,curl(符合 HTTP 1.1)通常可以解决问题:

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

【讨论】:

  • wget 支持 HTTP 1.1 since 2011
  • 谢谢。不知道发生了什么,但 wget 不会为我发送标题。卷曲工作正常。
  • @DavidSiegal 如何使用 curl 从google drive 下载文件。我用代码curl -u email@gmail.com:pass https://drive.google.com/drive/u/0/my-drive/3521.jpg > 3521.jpg给我下载了一个文件,但是打不开?
  • 建议在命令中只指定用户名,让它询问密码然后输入。只是为了防止在命令历史记录中看到密码。
  • @berbt 关于 wget 支持 HTTP 1.1 的维基百科链接从简洁的修订评论 "Mention support for HTTP/1.1" 获取其来源。目前尚不清楚这是否意味着全部或部分支持。官方Wget FAQ说的是后者。
【解决方案3】:

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

我按照@thomasbabuj 建议的链接最终弄明白了。

您应该尝试添加--auth-no-challenge 并按照@thomasbabuj 的建议替换您的密码输入

wget --auth-no-challenge --user=myusername --ask-password https://test.mydomain.com/files/myfile.zip

【讨论】:

  • man wget on --auth-no-challenge:“不建议使用此选项,仅用于支持一些不知名的服务器,它们从不发送 HTTP 身份验证挑战,但接受未经请求的身份验证信息,例如, 除了基于表单的身份验证。”
  • 是的,很好的输入。我尽可能使用 curl,但如果 wget 是必须的,--auth-no-challenge 在某些自动化环境中是必须的。我不同意“晦涩的服务器”表示法。
【解决方案4】:

您可以尝试使用 HTTP 而不是 HTTPS 使用相同的地址。请注意,这确实使用 HTTP 而不是 HTTPS,并且只有某些站点可能支持此方法。

示例地址:https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.3.0-amd64-netinst.iso

wget http://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.3.0-amd64-netinst.iso

*注意http:// 而不是https://

这可能是不推荐的:)

如果可以,请尝试使用 curl。


编辑:

仅供参考,使用用户名(并提示输入密码)的示例是:

curl --user $USERNAME -O http://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.3.0-amd64-netinst.iso

-O 在哪里

 -O, --remote-name
              Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut off.)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 2017-02-13
    • 1970-01-01
    • 2021-11-11
    • 2020-02-07
    相关资源
    最近更新 更多