简体   繁体   English

Apache Commons FTPClient 未从源文件中检索所有字节

[英]Apache Commons FTPClient Not Retrieving All Bytes From Source File

I have a fairly basic 3.8.0 FTPClient use case:我有一个相当基本的3.8.0 FTPClient用例:

FTPClient ftpClient = new FTPClient()

ftpClient.connect(hostName, hostPort)

if(FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
  ftpClient.setFileType(FTP.BINARY_FILE_TYPE)
  ftpClient.login(userName, password)

  FileOutputStream fos = new FileOutputStream("localFile.txt")

  ftpClient.retrieve("remoteFile.zip", fos)
}

The problem I have is that the resulting local file is always ~1400 Bytes smaller than the remote source file:我遇到的问题是生成的本地文件总是比远程源文件小 ~1400 字节:

source file size: 134,914,722
dest file size:   134,913,316

This doesn't seem to be a server problem since the standard linux ftp command retrieves the entire file.这似乎不是服务器问题,因为标准 linux ftp 命令检索整个文件。

It also doesn't seem to be OutputStream related because I have the same problem when I pull the file contents into memory:它似乎也与OutputStream无关,因为当我将文件内容拉入 memory 时,我遇到了同样的问题:

//still too small
Byte[] fileContents = ftpClient.retrieveFileStream("remoteFile.zip").readAllBytes()

What would cause the apache commons FTPClient to allow connectivity and file download but not exhaustively retrieve all bytes from the source file?什么会导致 apache commons FTPClient 允许连接和文件下载,但不能从源文件中彻底检索所有字节?

Thank you in advance for your consideration and response.预先感谢您的考虑和回复。

The problem was the ordering of setFileType ;问题是setFileType的顺序; it should have come after login instead of before.它应该在login之后而不是之前。

ftpClient.connect(...

ftpClient.login(...

ftpClient.setFileType(FTP.BINARY_FILE_TYPE)

The file coming in smaller was likely due to charset interpretations of the raw zip file.文件变小可能是由于原始 zip 文件的字符集解释。

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

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