Apache Commons Net FTP is uploading corrupted files

前端 未结 3 793
-上瘾入骨i
-上瘾入骨i 2020-12-06 02:13

I\'m trying to use Apache Commons Net for FTP file transfers.

Problem is files are intermittently arriving at the server corrupt. By \'corrupt\' I mean that WinRAR t

3条回答
  •  无人及你
    2020-12-06 02:51

    Commons FTP defaults to Ascii file types. You want to set it to Binary when dealing with binary data like a ZIP file.

    From http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html

    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 .

    You want to do setFileType(FTP.BINARY_FILE_TYPE) before you send the file.

提交回复
热议问题