问题描述
我正在使用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.
最新建议是:
As因此,不同的FTP服务器使用不同的语法支持不同的校验和命令。 哈希
, XSHA1
, XSHA256
, XSHA512
, XMD5
, MD5
, XCRC
,仅举几例。您需要检查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, if any, your FTP server supports.
您可以使用WinSCP进行测试。 WinSCP支持所有前面提到的命令。测试其或。如果它们有效,请,并检查WinSCP针对您的服务器使用了什么命令和语法。 / p>
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 :
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服务器中计算文件校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!