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
本文详细解析了Apache Commons Net库中FTPClient类的使用方法,重点介绍了文件传输类型ASCII_FILE_TYPE与BINARY_FILE_TYPE的区别。ASCII_FILE_TYPE适用于文本文件,会进行格式转换以适应不同操作系统;而BINARY_FILE_TYPE用于二进制文件,不进行任何转换,适用于大多数文件传输场景。
6600

被折叠的 条评论
为什么被折叠?



