我应该期望这些md5sum相同吗?
url = 'http://stackoverflow.com/opensearch.xml'
shl = paste0('curl -s ', url, '|md5sum')
shell(shl, intern = T)
#"1dbeef7406e5054197382916ff72e29b *-"
fl = 'temp.xml'
download.file(url = url, destfile = fl, mode = 'wb')
tools::md5sum(fl)
#"96bdf6d80c0bb6e27620079e2f6f7237"
如果没有,通常可以比较这样的文件吗?
或者如果源不提供校验和,是否还有另一种方法来检查文件在下载过程中是否未损坏?
更新:
url = 'https://www.ncl.ucar.edu/Applications/Data/bin/latlon.bin'
shl = paste0('curl -sL ', url, '|md5sum')
shell(shl, intern = T)
#"d41d8cd98f00b204e9800998ecf8427e *-"
fl = 'temp'
download.file(url = url, destfile = fl, mode = 'wb')
tools::md5sum(fl)
#"1a1eeb7a09418f047588148395096b91"
如果文件为.bin
,则似乎会返回不同的md5值
答案 0 :(得分:3)
您正在比较两个不同的文件-curl
不会自动跟随重定向
curl -i http://stackoverflow.com/opensearch.xml [13:00:20]
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: https://stackoverflow.com/opensearch.xml
X-Request-Guid: 99819f8c-f481-4295-b527-f586b9e27d22
Content-Security-Policy: upgrade-insecure-requests; frame-ancestors 'self'
Accept-Ranges: bytes
Age: 0
Content-Length: 157
Accept-Ranges: bytes
Date: Fri, 14 Jun 2019 17:00:23 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-lga21947-LGA
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1560531623.276827,VS0,VE3
Vary: Fastly-SSL
X-DNS-Prefetch-Control: off
Set-Cookie: prov=48b775d0-60fb-3f52-5066-61fe6fab27ca; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://stackoverflow.com/opensearch.xml">here</a>.</h2>
</body></html>
使用-L跟随重定向:
curl -sL http://stackoverflow.com/opensearch.xml | md5 [13:00:23]
96bdf6d80c0bb6e27620079e2f6f7237