reason
First, this problem is due to the way the FTP protocol defines data transmission, and when a Java FTP client uses ASCII transmission, some uploaded files are found to be corrupted.
The FTP protocol provides two modes of transmission, namely, ASCII and binary: ASCII, this mechanism means that the contents of the file are adjusted when it is ASCII text for the transmitted content, and sometimes the file is corrupted, and the ASCII method discards certain string bits in the file, so it is not guaranteed that every bit of the file data is important.
Binary mode, the first binary way to ensure that the file content all data bits are important.
Authenticated files with a file type that is not text content are corrupted by using the ASCII transfer method.
Sample Code (note ftp.binary_file_type/ftp.ascii_file_type):
/** * Uploading resources to a remote server * @param destresource upload File Object * @return {true: Success; false: Failed} * @throws IOException IOException/Pub Lic boolean uploadfile (File destresource) throws IOException {InputStream ins = (new FileInputStream (Destresource)); Ftpc Lient.setfiletype (Ftp.binary_file_type); Ftpclient.setfiletype (Ftp.ascii_file_type); Ftpclient.changeworkingdirectory ("tmp"); Boolean rtnflag = Ftpclient.storefile (Destresource.getname (), INS); Ins.close (); return rtnflag; }