比较本地文件与远程文件
我遇到以下问题:我有一个本地 .zip
文件和一个位于服务器上的 .zip
文件。我需要检查服务器上的.zip
文件是否与本地不同;如果不是,我需要从服务器中提取新的。我的问题是如何在不从服务器下载文件并在本地比较它们的情况下比较它们?
我可以在创建 .zip
文件时为服务器上的 zip 文件创建 MD5 哈希值,然后将其与本地 .zip
文件的 MD5 进行比较,但是更简单的方法?
I have the following problem: I have a local .zip
file and a .zip
file located on a server. I need to check if the .zip
file on the server is different from the local one; if they are not I need to pull the new one from the server. My question is how do I compare them without downloading the file from the server and comparing them locally?
I could create an MD5 hash for the zip file on the server when creating the .zip
file and then compare it with the MD5 of my local .zip
file, but is there a simpler way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答:你不能。
长答案:为了与服务器上的 zip 文件进行比较,必须有人读取该文件。您可以在本地执行此操作(这将涉及拉取它),也可以要求服务器为您执行此操作。可以在服务器上运行代码吗?
编辑
如果可以在服务器上运行Python,为什么不对文件进行散列并比较散列呢?
然后将
hashfile
的内容与本地生成的哈希进行比较?另一种编辑
您要求一种更简单的方法。以抽象的方式思考一下:
因此,您需要进行某种哈希处理。鉴于此,我认为上述内容非常简单。
Short answer: You can't.
Long answer: To compare with the zip file on the server, someone has to read that file. Either you can do that locally, which would involve pulling it, or you can ask the server to do it for you. Can you run code on the server?
Edit
If you can run Python on the server, why not hash the file and compare hashes?
and then compare the contents of
hashfile
with a locally-generated hash?Another edit
You asked for a simpler way. Think about this in an abstract way for a moment:
Therefore, you need to do some sort of hashing. Given that, I think the above is pretty simple.
我想知道如果是这样的话,您打算如何在本地比较它们。您可以应用相同的逻辑来远程比较它们。
I would like to know how you intend to compare them locally, if it were the case. You can apply the same logic to compare them remotely.
您可以使用 ssh 登录并为远程文件生成 md5 哈希值,并为当前本地文件生成 md5 哈希值。如果 md5 匹配,则文件相同,否则文件不同。
You can log in using ssh and make a md5 hash for the file remotely and a md5 hash for the current local file. If the md5s are matching the files are identicaly, else they are different.