diff --git a/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java b/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java index eb7c62c..c9ec082 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java +++ b/pnkx-common/src/main/java/com/pnkx/common/ftp/FtpTool.java @@ -76,7 +76,13 @@ public class FtpTool { ftpClient.setConnectTimeout(TIMEOUT); ftpClient.connect(HOST, PORT); ftpClient.login(USER_NAME, PWD); - ftpClient.setControlEncoding("UTF-8"); + //开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就用本地编码(ISO-8859-1) + if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) { + ftpClient.setControlEncoding("UTF-8"); + } else { + //FTP协议里面,规定文件名编码为iso-8859-1 + ftpClient.setControlEncoding("ISO-8859-1"); + } ftpClient.setFileType(FTP.BINARY_FILE_TYPE); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { log.error("连接FTP失败,用户名或密码错误;用户名:{};密码{}", USER_NAME, PWD);