tags:

views:

309

answers:

3

Is it possible to get the md5 of a file on a remote server? If so how?

+3  A: 

Well depends what you mean. There are two ways:

  1. You connect to the remote server and calculate the hash there (like ssh to the server).

  2. Get (download) the file and compute the hash.

Obviously to calculate the hash of a file you have to read the contents of the file.

Felix Kling
I'm not very good with ssh. Is there an example you could provide for example 1? Like.. $a = exec('some shell stuff to return the file info');
John
+2  A: 

It's not possible without downloading it, or the remote server providing the information (web service, HTML page, etc.)

You can use md5(file_get_contents("http://remotelocation/file")) to download the file and calculate the md5 hash if your PHP installation is configured to open remote streams. But that will download the complete file.

Vinko Vrsalovic
+1 for the remote streams idea.
Ben S
I tried this, but it's not the md5 of the actual file, it's the md5 of the actual output.
John
If you are talking about a server-side script such as a `.php` file, you cannot get the MD5 stamp of it, or the source code inside it in general, via HTTP. That would be a security disaster if you could! You would have to use the appropriate connection you use to access the source on the server, eg. [S]FTP.
bobince
+4  A: 

how about md5_file("http://remotelocation/file")

newacct
i didnt know about this if this command is a valid in php then +1
streetparade
Most filesystem functions apply to streams, including HTTP.
mrclay
Keep in mind that this will transfer the whole content of the remote file to your server. May be feasible, may be not.
VolkerK