From 735228fcb151e78c044f97e1133e287835c3fe29 Mon Sep 17 00:00:00 2001 From: emaisi Date: Wed, 4 May 2022 13:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dftp=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E8=BD=BD=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/core/client/ftp/FtpFileClient.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java index d50bc8501..f877ce649 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java @@ -27,9 +27,11 @@ public class FtpFileClient extends AbstractFileClient { @Override protected void doInit() { - // 补全风格。例如说 Linux 是 /,Windows 是 \ - if (!config.getBasePath().endsWith(File.separator)) { - config.setBasePath(config.getBasePath() + File.separator); + //如果路径配置\a\test,替换成/a/test,替换方法已经处理为null情况 + config.setBasePath(StrUtil.replace(config.getBasePath(),StrUtil.BACKSLASH,StrUtil.SLASH)); + // ftp是的路径是"/" 结尾 + if (!config.getBasePath().endsWith(StrUtil.SLASH)) { + config.setBasePath(config.getBasePath() + StrUtil.SLASH); } // 初始化 Ftp 对象 this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(), @@ -60,7 +62,7 @@ public class FtpFileClient extends AbstractFileClient { public byte[] getContent(String path) { String filePath = getFilePath(path); String fileName = FileUtil.getName(filePath); - String dir = StrUtil.removeSuffix(path, fileName); + String dir = StrUtil.removeSuffix(filePath, fileName); ByteArrayOutputStream out = new ByteArrayOutputStream(); ftp.download(dir, fileName, out); return out.toByteArray(); @@ -70,4 +72,4 @@ public class FtpFileClient extends AbstractFileClient { return config.getBasePath() + path; } -} +} \ No newline at end of file