wget 未检索正确大小的文件(文件损坏或不完整?)

wget 未检索正确大小的文件(文件损坏或不完整?)

我不明白...

实际的下载链接似乎不是 http 链接,而是一些 Javascript 操作?

javascript:SendFileDownloadCall('PRODIMAGES.CIF.zip','PRODIMAGES.CIF.zip');

所以手动下载后,我去浏览器的下载历史记录中复制直接链接 https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL.TXT.zip

我将 URL 以及我的网站凭据输入到 wget 中:

wget -q --user=XXXX --password=XXXX "https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL.TXT.zip" -o STDPRICE.zip

后来,我发现添加 --user 和 --password 没有什么区别,所以我省略了:

[root@server datafiles]# wget "https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL" -O STDPRICE.zip
--2019-09-15 19:53:29--  https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL
Resolving au.ingrammicro.com (au.ingrammicro.com)... 104.98.45.15
Connecting to au.ingrammicro.com (au.ingrammicro.com)|104.98.45.15|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: /_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL [following]
--2019-09-15 19:53:29--  https://au.ingrammicro.com/_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL
Reusing existing connection to au.ingrammicro.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 85341 (83K) [text/html]
Saving to: ‘STDPRICE.zip’

100%[===================================================================================================================================================================================================>] 85,341       405KB/s   in 0.2s

2019-09-15 19:53:30 (405 KB/s) - ‘STDPRICE.zip’ saved [85341/85341]

无论如何,我得到的文件不是与通过人工点击并从网站下载得到的文件等效的文件,而是得到了一个小得令人难以置信的文件。

证实了我的恐惧,当我尝试解压缩时,我得到:

$ [root@server datafiles]# unzip STDPRICE.zip
Archive:  STDPRICE.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of STDPRICE.zip or
        STDPRICE.zip.zip, and cannot find STDPRICE.zip.ZIP, period.

档案检查:

$ [root@server datafiles]# file STDPRICE.zip
STDPRICE.zip: HTML document, UTF-8 Unicode text, with very long lines, with CRLF line terminators

那么 wget 实际上下载了一个以文件形式呈现的 HTML 文件.txt.zip?有人可以启发我吗?

答案1

该网站正在将您重定向到登录页面:

HTTP request sent, awaiting response... 302 Moved Temporarily
Location: /_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL [following]
--2019-09-15 19:53:29--  https://au.ingrammicro.com/_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL

它可能不接受您作为基本身份验证提供的凭据(这是 wget 发送的),而是使用会话 cookie。您可以尝试从浏览器中提取 cookie(登录时)并使用 wget ( --load-cookies) 发送它们。他们还可能会关注您也可能尝试修改的请求的其他方面(例如用户代理)。

如果您可以使用curl代替,请打开检查器(Ctrl+Shift+I),转到网络选项卡,下载文件,右键单击请求列表中的下载条目,将鼠标悬停在“复制”上,然后选择“复制为cURL”,现在剪贴板上的命令将包含 cookie。

相关内容