From 735228fcb151e78c044f97e1133e287835c3fe29 Mon Sep 17 00:00:00 2001 From: emaisi Date: Wed, 4 May 2022 13:20:34 +0800 Subject: [PATCH 1/4] =?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 From 472da026dee653b5770990b8e3daaca557d3af78 Mon Sep 17 00:00:00 2001 From: emaisi Date: Wed, 4 May 2022 22:46:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/framework/file/core/client/ftp/FtpFileClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 f877ce649..f33718f54 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,9 @@ public class FtpFileClient extends AbstractFileClient { @Override protected void doInit() { - //如果路径配置\a\test,替换成/a/test,替换方法已经处理为null情况 + // 把配置的 \ 替换成 /,如果路径配置 \a\test,替换成 /a/test,替换方法已经处理 null 情况 config.setBasePath(StrUtil.replace(config.getBasePath(),StrUtil.BACKSLASH,StrUtil.SLASH)); - // ftp是的路径是"/" 结尾 + // ftp的路径是 / 结尾 if (!config.getBasePath().endsWith(StrUtil.SLASH)) { config.setBasePath(config.getBasePath() + StrUtil.SLASH); } From bddd19318542bc162e4821b3668a740a6806e4a6 Mon Sep 17 00:00:00 2001 From: emaisi Date: Wed, 4 May 2022 22:46:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/framework/file/core/client/ftp/FtpFileClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 f877ce649..6f305e342 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,9 @@ public class FtpFileClient extends AbstractFileClient { @Override protected void doInit() { - //如果路径配置\a\test,替换成/a/test,替换方法已经处理为null情况 + // 把配置的 \ 替换成 /, 如果路径配置 \a\test, 替换成 /a/test, 替换方法已经处理 null 情况 config.setBasePath(StrUtil.replace(config.getBasePath(),StrUtil.BACKSLASH,StrUtil.SLASH)); - // ftp是的路径是"/" 结尾 + // ftp的路径是 / 结尾 if (!config.getBasePath().endsWith(StrUtil.SLASH)) { config.setBasePath(config.getBasePath() + StrUtil.SLASH); } From 12ede349faecfd2060b8ddf8b34f5e7bac609255 Mon Sep 17 00:00:00 2001 From: emaisi Date: Thu, 5 May 2022 07:31:56 +0000 Subject: [PATCH 4/4] =?UTF-8?q?ftp=E7=9A=84=E5=9C=A8=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E8=B6=85=E6=97=B6=E7=9A=84=E9=87=8D=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/framework/file/core/client/ftp/FtpFileClient.java | 3 +++ 1 file changed, 3 insertions(+) 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 f0f9e130e..4ad345bdc 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 @@ -44,6 +44,7 @@ public class FtpFileClient extends AbstractFileClient { String filePath = getFilePath(path); String fileName = FileUtil.getName(filePath); String dir = StrUtil.removeSuffix(filePath, fileName); + ftp.reconnectIfTimeout(); boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content)); if (!success) { throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath)); @@ -55,6 +56,7 @@ public class FtpFileClient extends AbstractFileClient { @Override public void delete(String path) { String filePath = getFilePath(path); + ftp.reconnectIfTimeout(); ftp.delFile(filePath); } @@ -64,6 +66,7 @@ public class FtpFileClient extends AbstractFileClient { String fileName = FileUtil.getName(filePath); String dir = StrUtil.removeSuffix(filePath, fileName); ByteArrayOutputStream out = new ByteArrayOutputStream(); + ftp.reconnectIfTimeout(); ftp.download(dir, fileName, out); return out.toByteArray(); }