简体   繁体   English

使用 Java 对 FTP 文件进行校验和

[英]Checksum on FTP file using Java

I'm have created a java app which transfers files from FTP location to HDFS.我已经创建了一个 java 应用程序,它将文件从 FTP 位置传输到 HDFS。 This is done using copying the file first to temp folder in the edge node then move it to HDFS (cloudera cluster).这是通过首先将文件复制到边缘节点中的临时文件夹然后将其移动到 HDFS(cloudera 集群)来完成的。 Currently I'm doing byte check on the file - I'm comparing total file size in bytes of the FTP file and the copied HDFS file.目前我正在对文件进行字节检查 - 我正在比较 FTP 文件和复制的 HDFS 文件的总文件大小(以字节为单位)。 I want to implement checksum.我想实现校验和。 I have googled but I couldn't get any answers.我已经用谷歌搜索,但我无法得到任何答案。 Please let me know if you any ideas.如果您有任何想法,请告诉我。 (FTP server is a Windows machine where we enabled FTP) (FTP 服务器是 Windows 机器,我们启用了 FTP)

If you want to calculate checksum, I think that the easiest solution is to use Apache Common Codec.如果要计算校验和,我认为最简单的解决方案是使用 Apache Common Codec。

String sha256hex = org.apache.commons.codec.digest.DigestUtils.sha256Hex(stringText); 

Another alternative is Guava which has an easy-to-use suite of Hashing utilities.另一种选择是 Guava,它具有易于使用的散列实用程序套件。 For example, to hash a string using SHA256 as a hex-string you would simply do:例如,对于 hash 使用 SHA256 作为十六进制字符串的字符串,您只需执行以下操作:

final String hashed = Hashing.sha256()
        .hashString("your input", StandardCharsets.UTF_8)
        .toString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM