使用JSCH在远程服务器上获取MD5校验和 [英] Getting MD5 checksum on the remote server using JSCH

查看:463
本文介绍了使用JSCH在远程服务器上获取MD5校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,要求将文件从远程SFTP服务器传输到本地计算机,反之亦然.在文件传输过程中,我要确保传输过程中不会丢失任何数据包,因此想法是在传输之前在远程文件(位于sftp服务器中)上运行MD5校验和,然后开始传输过程.传输完成后,在本地文件上运行md5并比较两个校验和.

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.

我正在使用JSCH连接到sftp服务器,代码在java中.但是我不知道如何在SFTP服务器中的远程文件上运行md5.我的代码必须在远程文件上执行MD5进行转移.有关如何实现此目标的任何想法.

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.

推荐答案

大多数Unix系统都有md5sum命令.您可以在远程服务器上调用它以检索哈希.

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

Jsch网站包含示例,该示例显示了如何调用远程服务器上的命令.可以很容易地将其修改为运行md5sum命令.

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.

这篇关于使用JSCH在远程服务器上获取MD5校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆