Commit d8a242629b4d4b3ccc6ec0e492552021c8e2dcd8

Authored by YunaiV
2 parents 7f5788ae 72404782

Merge branch 'feature/1.6.2' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/1.6.2

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<FtpFileClientConfig> {
27 27  
28 28 @Override
29 29 protected void doInit() {
30   - // 补全风格。例如说 Linux 是 /,Windows 是 \
31   - if (!config.getBasePath().endsWith(File.separator)) {
32   - config.setBasePath(config.getBasePath() + File.separator);
  30 + // 把配置的 \ 替换成 /, 如果路径配置 \a\test, 替换成 /a/test, 替换方法已经处理 null 情况
  31 + config.setBasePath(StrUtil.replace(config.getBasePath(), StrUtil.BACKSLASH, StrUtil.SLASH));
  32 + // ftp的路径是 / 结尾
  33 + if (!config.getBasePath().endsWith(StrUtil.SLASH)) {
  34 + config.setBasePath(config.getBasePath() + StrUtil.SLASH);
33 35 }
34 36 // 初始化 Ftp 对象
35 37 this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
... ... @@ -42,6 +44,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
42 44 String filePath = getFilePath(path);
43 45 String fileName = FileUtil.getName(filePath);
44 46 String dir = StrUtil.removeSuffix(filePath, fileName);
  47 + ftp.reconnectIfTimeout();
45 48 boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
46 49 if (!success) {
47 50 throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
... ... @@ -53,6 +56,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
53 56 @Override
54 57 public void delete(String path) {
55 58 String filePath = getFilePath(path);
  59 + ftp.reconnectIfTimeout();
56 60 ftp.delFile(filePath);
57 61 }
58 62  
... ... @@ -60,8 +64,9 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
60 64 public byte[] getContent(String path) {
61 65 String filePath = getFilePath(path);
62 66 String fileName = FileUtil.getName(filePath);
63   - String dir = StrUtil.removeSuffix(path, fileName);
  67 + String dir = StrUtil.removeSuffix(filePath, fileName);
64 68 ByteArrayOutputStream out = new ByteArrayOutputStream();
  69 + ftp.reconnectIfTimeout();
65 70 ftp.download(dir, fileName, out);
66 71 return out.toByteArray();
67 72 }
... ... @@ -70,4 +75,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
70 75 return config.getBasePath() + path;
71 76 }
72 77  
73 78 -}
  79 +}
74 80 \ No newline at end of file
... ...