From b86961c9d4c26d4fa7b2af4f053d70aea9da9b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A3=B4=E6=B5=A9=E5=AE=87?= <617594538@qq.com> Date: Wed, 8 May 2024 16:56:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20FTP=E4=B8=8A=E4=BC=A0=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pnkx/common/ftp/FtpTool.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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);