FTP 上传/下载文件大小为0、内容为空的解决办法

FTP包:org.apache.commons.net.ftp.FTPClient

The default settings for FTPClient are for it to use FTP.ASCII_FILE_TYPE , FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE , and FTP.FILE_STRUCTURE . The only file types directly supported are FTP.ASCII_FILE_TYPE and FTP.BINARY_FILE_TYPE . Because there are at least 4 different EBCDIC encodings, we have opted not to provide direct support for EBCDIC. To transfer EBCDIC and other unsupported file types you must create your own filter InputStreams and OutputStreams and wrap them around the streams returned or required by the FTPClient methods. FTPClient uses the NetASCII filter streams to provide transparent handling of ASCII files. We will consider incorporating EBCDIC support if there is enough demand.
默认文件传输类型为ASCII_FILE_TYPE ,如果是普通文件上传下载就选BINARY_FILE_TYPE
ASCII_FILE_TYPE会更改文本内容,更改回车、空格以适应不同的操作系统,而BINARY_FILE_TYPE不会操作文本,所以推荐

ASCII_FILE_TYPE

public static final int ASCII_FILE_TYPE
A constant used to indicate the file(s) being transferred should be treated as ASCII. This is the default file type. All constants ending in FILE_TYPE are used to indicate file types.
See Also:
Constant Field Values

BINARY_FILE_TYPE

public static final int BINARY_FILE_TYPE
A constant used to indicate the file(s) being transferred should be treated as a binary image, i.e., no translations should be performed. All constants ending in FILE_TYPE are used to indicate file types.
See Also:
Constant Field Values

参考:FTPClient官方文档

你可能感兴趣的:(java基础)