r - 比较在线文件的 md5sum 和本地下载的文件

标签 r windows cmd md5sum

我应该期望这些 md5sums 相同吗?

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 值

最佳答案

您正在比较两个不同的文件 - 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

关于r - 比较在线文件的 md5sum 和本地下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56602271/

相关文章:

r - 安装和运行rcpp时出错

r - utils::View显示的数字可以格式化吗?

r - 在 Shiny 中居中自定义数据表容器列标题

Java -Jar "my project"未在 C.P 中执行(Windows)

r - 拉万 : how to specify interaction terms in SEM

windows - 使用命令行的引用参数时如何进行条件检查(if 命令)?

linux - 多线程 Linux 与 Windows

windows - 在 Amazon EC2 Windows 2008 镜像上运行 Win32 可执行文件

c - 在实际 EOF 之前的 cmd 转发输出中的文件结尾

windows - 批处理字符串操作中的进度条