Commit 12ede349faecfd2060b8ddf8b34f5e7bac609255

Authored by emaisi
Committed by Gitee
1 parent 247b8931

ftp的在操作之前添加一个判断超时的重试。

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<FtpFileClientConfig> { @@ -44,6 +44,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
44 String filePath = getFilePath(path); 44 String filePath = getFilePath(path);
45 String fileName = FileUtil.getName(filePath); 45 String fileName = FileUtil.getName(filePath);
46 String dir = StrUtil.removeSuffix(filePath, fileName); 46 String dir = StrUtil.removeSuffix(filePath, fileName);
  47 + ftp.reconnectIfTimeout();
47 boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content)); 48 boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
48 if (!success) { 49 if (!success) {
49 throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath)); 50 throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
@@ -55,6 +56,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { @@ -55,6 +56,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
55 @Override 56 @Override
56 public void delete(String path) { 57 public void delete(String path) {
57 String filePath = getFilePath(path); 58 String filePath = getFilePath(path);
  59 + ftp.reconnectIfTimeout();
58 ftp.delFile(filePath); 60 ftp.delFile(filePath);
59 } 61 }
60 62
@@ -64,6 +66,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { @@ -64,6 +66,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
64 String fileName = FileUtil.getName(filePath); 66 String fileName = FileUtil.getName(filePath);
65 String dir = StrUtil.removeSuffix(filePath, fileName); 67 String dir = StrUtil.removeSuffix(filePath, fileName);
66 ByteArrayOutputStream out = new ByteArrayOutputStream(); 68 ByteArrayOutputStream out = new ByteArrayOutputStream();
  69 + ftp.reconnectIfTimeout();
67 ftp.download(dir, fileName, out); 70 ftp.download(dir, fileName, out);
68 return out.toByteArray(); 71 return out.toByteArray();
69 } 72 }