From e604379a1802ceb9dd632b7bf3f7d6d7c0c4c5e1 Mon Sep 17 00:00:00 2001 From: zhangyx <2484529215@qq.com> Date: Fri, 16 May 2025 11:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFTP=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E6=88=96=E8=B7=AF=E5=BE=84=E4=B8=BA=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E9=A2=84=E8=A7=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/java/cn/keking/utils/FtpUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/cn/keking/utils/FtpUtils.java b/server/src/main/java/cn/keking/utils/FtpUtils.java index 8a736fd4..d12e71be 100644 --- a/server/src/main/java/cn/keking/utils/FtpUtils.java +++ b/server/src/main/java/cn/keking/utils/FtpUtils.java @@ -1,6 +1,7 @@ package cn.keking.utils; import cn.keking.config.ConfigConstants; +import jodd.util.URLDecoder; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; @@ -44,7 +45,13 @@ public class FtpUtils { URL url = new URL(ftpUrl); String host = url.getHost(); int port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort(); - String remoteFilePath = url.getPath(); + String path = url.getPath(); + int fileNameStartIndex = path.lastIndexOf("/"); + int fileNameLatestIndex = path.lastIndexOf("."); + String startPath = path.substring(0, fileNameStartIndex+1); + String endPath = path.substring(fileNameLatestIndex); + String fileName = path.substring(fileNameStartIndex+1, fileNameLatestIndex); + String remoteFilePath = startPath+ URLDecoder.decode(fileName, StringUtils.isEmpty(ftpControlEncoding) ? "UTF-8" : ftpControlEncoding) + endPath; LOGGER.debug("FTP connection url:{}, username:{}, password:{}, controlEncoding:{}, localFilePath:{}", ftpUrl, username, password, controlEncoding, localFilePath); FTPClient ftpClient = connect(host, port, username, password, controlEncoding); OutputStream outputStream = Files.newOutputStream(Paths.get(localFilePath)); -- Gitee