Getting MD5 checksum on the remote server using JSCH

雨燕双飞 提交于 2019-12-09 01:38:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!