使用 Apache FtpClient 计算 FTP 服务器中的文件校验和 [英] Calculate file checksum in FTP server using Apache FtpClient

查看:42
本文介绍了使用 Apache FtpClient 计算 FTP 服务器中的文件校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache Commons Net 的 FtpClient 将视频上传到 FTP 服务器.为了检查文件是否真的传输成功,我想计算远程文件的校验和,但不幸的是我发现没有可以使用的相关 API.

我的问题是:ftp服务器是否需要计算文件校验和?
如果是,如何在FtpClient中获取校验和?
如果答案是否定的,FtpClient如何知道文件是否真的已经成功并完全传输了?

I am using FtpClient of Apache Commons Net to upload videos to FTP server. To check if the file has really been successfully transferred, I want to calculate the checksum of remote file, but unfortunately I found there is no related API I could use.

My question is: Whether there is a need to calculate file checksum in ftp server?
If the answer is yes, how to get checksum in FtpClient?
If the answer is no, how do FtpClient know if the file has really been successfully and completely transferred?

推荐答案

使用 FTP,我建议验证上传,如果可能.

With FTP, I'd recommend to verify the upload, if possible.

问题在于没有广泛的标准 API 用于计算 FTP 的校验和.

The problem is that there's no widespread standard API for calculating checksum with FTP.

对于 FTP 的校验和计算命令有很多建议.没有一个被接受.

There are many proposals for checksum calculation command for FTP. None were accepted yet.

最新提案是:
https://datatracker.ietf.org/doc/html/草稿-bryan-ftpext-hash-02

因此,不同的 FTP 服务器使用不同的语法支持不同的校验和命令.HASHXSHA1XSHA256XSHA512XMD5MD5XCRC 等等.您需要检查您的 FTP 服务器支持什么,如果有的话.

As a consequence, different FTP servers support different checksum commands, with a different syntax. HASH, XSHA1, XSHA256, XSHA512, XMD5, MD5, XCRC, to name some. You need to check what, and if any at all, your FTP server supports.

您可以使用 WinSCP 进行测试.WinSCP 支持所有前面提到的命令.测试其校验和计算函数checksum 脚本命令.如果它们有效,请启用日志记录并检查 WinSCP 对您的服务器使用的命令和语法.

You can test that with WinSCP. The WinSCP supports all the previously mentioned commands. Test its checksum calculation function or checksum scripting command. If they work, enable logging and check what command and what syntax WinSCP uses against your server.

> 2015-04-28 09:19:16.558 XSHA1 /test/file.dat
< 2015-04-28 09:19:22.778 213 a98faefdb2c36ca352a2d9b01668aec6b641cf4b 

然后使用Apache Commons Net执行命令sendCommand 方法:

Then execute the command using Apache Commons Net sendCommand method:

if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("XSHA1", "filename"))
{
    String[] reply = ftpClient.getReplyStrings();
}

(我是 WinSCP 的作者)

如果您的服务器不支持任何校验和命令,那么您没有太多选择:

If your server does not support any of the checksum commands, you do not have many options:

  • 下载文件并在本地查看.
  • 使用加密 (TLS/SSL) 时,文件在传输过程中损坏的可能性会大大降低.否则,接收方(在这种情况下为服务器)将无法解密数据.因此,如果您确定文件传输完成(没有解密错误并且上传文件的大小与原始本地文件的大小相同),则可以确定上传的文件是正确的.

这篇关于使用 Apache FtpClient 计算 FTP 服务器中的文件校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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