views:

47

answers:

3

Hi, 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 in 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,is there a simpler way ?

+1  A: 

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?

import hashlib
with open( <path-to-file>, "rb" ) as theFile:
    m = hashlib.md5( )
    for line in theFile:
        m.update( line )
with open( <path-to-hashfile>, "wb" ) as theFile:
    theFile.write( m.digest( ) )

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:

  • You don't want to download the entire zip file.
  • Hence, you can't process the entire file locally (because that would involve reading all of it from the server, which is equivalent to downloading it!).
  • Hence, you need to do some processing on the server. Specifically, you want to come up with some small amount of data that 'encodes' the file, so that you can fetch this small amount of data without fetching the whole file.
  • But this is a hash!

Therefore, you need to do some sort of hashing. Given that, I think the above is pretty simple.

katrielalex
I can run code on the server, currently the file is served using FTP but I can use other protocols as well as log as I use python without third-party applications
John Retallack
Then I'd hash the file on the server and check that.
katrielalex
I just saw your edit above. Is this insufficiently simple?
katrielalex
A: 

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.

Rahul
I was thinking of using python filecmp module
John Retallack
A: 

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.

Teodor Pripoae