我正试图从以下网站下载通过Content Disposition:附件发送的kml文件:
http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us®ions=ia
使用wget和curl命令:
wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us®ions=ia
和
curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us®ions=ia
然而,它没有保存作为发送器的文件,而是只保存html内容,在传输结束时,它会被卡住。终端返回为:
$wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us®ions=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内容?
&
符号被解释为shell特殊字符,它会导致命令在后台运行(fork)。所以你应该逃避或引用它们:
curl -O -J -L 'http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us®ions=ia'
在上面的命令中,我们使用了完全引用。
输出中的以下几行表示有三个命令被分支到后台:
[1] 32260
[2] 32261
[3] 32262
左边的数字(括号内)是工作编号。您可以通过键入fg N
将作业置于前台,其中N
是作业的编号。右边的数字是进程ID。