要从服务器下载SOFA Statistics,我使用wget命令:
wget -c http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp
Run Code Online (Sandbox Code Playgroud)
在这种情况下,下载文件的文件名是download?source=files.如果我将该--output-document选项添加到命令,要将输出文件重命名为sofastatistics-latest.deb,则dpkg软件包无法识别下载文件的格式.
dpkg-deb: error: `sofastatistics-latest.deb' is not a debian format archive
Run Code Online (Sandbox Code Playgroud)
如何使用wget正确重命名下载的文件?
更新 - 2015年1月8日
使用提供的链接,下载的文件将始终为*.tar.gz.要获得真实姓名,只需添加--content-disposition选项(感谢@ 6EQUJ5!):
wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp
Run Code Online (Sandbox Code Playgroud)
但我需要一个*.deb文件,所以这里是@creaktive,我必须搜索*.deb文件链接.
感谢大家的答案!
Yau*_*ich 99
将标准输出重定向到任意文件名始终有效.正如man wget所说,你正在使用-O 正确地完成它
wget http://www.kernel.org/pub/linux/kernel/README -O foo
--2013-01-13 18:59:44-- http://www.kernel.org/pub/linux/kernel/README
Resolving www.kernel.org... 149.20.4.69, 149.20.20.133
Connecting to www.kernel.org|149.20.4.69|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12056 (12K) [text/plain]
Saving to: `foo'
100%[======================================================================================================================================>] 12,056 --.-K/s in 0.003s
2013-01-13 18:59:45 (4.39 MB/s) - `foo' saved [12056/12056]
Run Code Online (Sandbox Code Playgroud)
实际上,您必须在文件中获取HTML(通常可以使用man文件进行检查).
[编辑]
在您的情况下,客户端正在接收302 Found(您可以使用curl -v URL进行检查).
以下curl通过尊重3xx来做到这一点:
$ curl -L http://sourceforge.net/projects/sofastatistics/files/latest/download?source=files -o foo.deb
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 463 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
100 2035k 100 2035k 0 0 390k 0 0:00:05 0:00:05 --:--:-- 1541k
$ file foo.deb
foo.deb: gzip compressed data, was "sofastats-1.3.1.tar", last modified: Thu Jan 10 00:30:44 2013, max compression
Run Code Online (Sandbox Code Playgroud)
wget应该有类似的选项来容忍HTTP重定向.
6EQ*_*UJ5 20
如果您要从Web浏览器执行相同的下载,并且您注意到浏览器实际上正确命名了文件,则可以使用该--content-disposition选项为wget提供相同的行为:
wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp
Run Code Online (Sandbox Code Playgroud)
我的Debian手册页将此报告为"实验性"功能,但我不记得它不适合我:
--content-disposition
If this is set to on, experimental (not fully-functional) support for "Content-Disposition" headers is enabled. This can currently result in extra round-trips to the server
for a "HEAD" request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.
This option is useful for some file-downloading CGI programs that use "Content-Disposition" headers to describe what the name of a downloaded file should be.
Run Code Online (Sandbox Code Playgroud)
该链接指向重定向器,而不是最终目的地!因此,您要下载 HTML 并将其重命名为.deb. 杂乱的页面顶部有这样的内容:
现在,这是一个有效的链接(注意download前缀):
http://downloads.sourceforge.net/project/sofastatistics/sofastatistics/1.3.1/sofastats-1.3.1-1_all.deb ?r=http%3A%2F %2Fsourceforge.net%2Fprojects%2Fsofastatistics%2Ffiles%2Fsofastatistics%2F1.3.1%2F&ts=1358119361&use_mirror=ufpr
将此 URL 传递给wget. 另请注意,SourceForge 试图智取您,通过 User-Agent 字符串来访问操作系统。“wget”的最佳猜测似乎是 .tar.gz 包。所以,你应该更具体,请求 deb 文件!