使用wget下载时遇到“content-disposition”问题导致下载失败

5

我正在尝试从以下网站下载通过Content-Disposition:attachment发送的kml文件:

http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

使用wget和curl命令:
wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

并且

curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

然而,传输文件时它仅保存html内容,传输结束后卡住了。终端返回信息如下:

$wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia
[1] 32260
[2] 32261
[3] 32262
work@Aspire-V3-471:~$ --2016-05-13 19:37:54--  http://waterwatch.usgs.gov/index.php?m=real
Resolving waterwatch.usgs.gov (waterwatch.usgs.gov)... 2001:49c8:0:126c::56, 137.227.242.56
Connecting to waterwatch.usgs.gov (waterwatch.usgs.gov)|2001:49c8:0:126c::56|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.php?m=real.5[  <=>                                                                                                                                                  ] 41.637       174KB/s   in 0,2s   

2016-05-13 19:37:55 (174 KB/s) - ‘index.php?m=real.5’ saved [41637]

然后它卡住了,我需要按Ctrl+C。我得到的标题是

HTTP/1.1 200 OK
Date: Sat, 14 May 2016 00:19:21 GMT
Content-Disposition: attachment; filename="real_ia.kml"
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/vnd.google-earth.kml+xml
X-Frame-Options: SAMEORIGIN

我希望真正的' real_ia.kml '文件已经下载。使用curl命令会得到类似的结果。为什么它卡住了,只下载HTML内容呢?
1个回答

3

&符号被解释为shell特殊字符,它会导致命令在后台运行(分叉)。因此,您应该转义或引用它们:

curl -O -J -L 'http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia'

在上面的命令中,我们使用了全引用
你的输出中以下几行意味着三个命令被分叉到后台:
[1] 32260
[2] 32261
[3] 32262

左侧括号内的数字是作业编号。您可以通过键入fg N将作业带到前台,其中N是作业编号。右侧的数字是进程ID。


2
Ruslan Osmanov,你救了我们的一天!现在一切都可以通过以下命令运行:curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real\&w=kml\&r=us\&regions=ia(只是在这里发布以便让其他人清楚)非常感谢你! - adlzanchetta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接