问题
I am writing a application where the requirement is to transfer files from a remote SFTP server to the local machine and vice - versa. During the file transfer I want to make sure that no data packets are lost and corrupted in the transit.So the idea is to run a MD5 checksum on the remote file (residing in the sftp server) before the transfer and then start the transfer process. Once the transfer is done, run a md5 on the local file and compare the two checksums.
I am using JSCH to connect to sftp server and the code is in java.But I dont know how to run a md5 on the remote file residing in the SFTP server.My code has to do the MD5 on the remote file before the transfer takes place.Any idea on how to accomplish this please.
回答1:
Most Unix systems have an md5sum
command. You could invoke that on the remote server to retrieve the hash.
$ md5sum /tmp/test
34a27208f62ff3bdae031c9e8a354ac3 /tmp/test
The Jsch website contains an example that shows how to invoke a command on the remote server. This could easily be adapted to run the md5sum
command.
来源:https://stackoverflow.com/questions/16216902/getting-md5-checksum-on-the-remote-server-using-jsch