2013-01-13 106 views
49

要我用wget命令服务器下载SOFA统计:如何重命名的wget下载的文件?

wget -c http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

下载的文件在这种情况下,文件名是download?source=files。如果我的--output-document选项添加到命令,重命名输出文件sofastatistics-latest.deb,下载文件的格式不被dpkg包的认可。

dpkg-deb: error: `sofastatistics-latest.deb' is not a debian format archive 

如何正确使用wget重命名下载的文件?

更新 - 08年1月'15

随着所提供的链接下载的文件始终是.tar.gz之一*。要使用实名得到它只需添加--content-disposition选项,因为这(感谢@ 6EQUJ5!):

wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

但我需要一个* .deb文件,所以在这里是正确的@creaktive,我不得不寻找为* .deb文件链接。

感谢所有的答案!

+2

如果dpkg的说,它_really_不是Debian包...这是什么'file'说? – fge

+0

您提到的URL是一个HTML页面。 –

+0

我认为你接受了错误的答案。 – user83039

回答

1

即链接指向一个重定向器,而不是最终的目的地!所以你要下载HTML并将其重命名为.deb。杂乱的页面有这个顶部:

您的下载将开始在0秒... 下载的问题?请使用direct link,或尝试其它mirror

现在,是一个有效的链接(注意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

通过这个网址wget。 另外,还要注意SourceForge上试图智取你,通过用户代理字符串的客串业务系统。 “wget”的最佳猜测似乎是.tar.gz包。所以,你应该更具体,请求deb文件!

+0

这个软件有一个.tar.gz版本:http://sourceforge.net/projects/sofastatistics/files/sofastatistics/1.3.1/确保你选择.deb链接! – creaktive

59

标准输出的重定向到任意文件名总是工作。你是做正确的人的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] 

事实上,你必须在文件中得到一个HTML(通常可以用男子文件检查)。

[编辑]

在你的情况下客户端接收302找到(你可以用卷曲-v URL检查)。

下卷曲通过尊重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 

应该有类似的选项为wget的容忍HTTP重定向。

14

如果你是做从Web浏览器相同的下载,并且您会注意到浏览器实际正确命名的文件,你可以使用--content-disposition选项给wget的相同的行为:

wget --content-disposition http://sourceforge.net/projects/sofastatistics/files/latest/download?source=dlp 

我的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.