Commit 735228fcb151e78c044f97e1133e287835c3fe29

Authored by emaisi
1 parent 60f918da

修复ftp上传和下载的

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,9 +27,11 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
27 27
28 @Override 28 @Override
29 protected void doInit() { 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 // 初始化 Ftp 对象 36 // 初始化 Ftp 对象
35 this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(), 37 this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
@@ -60,7 +62,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { @@ -60,7 +62,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
60 public byte[] getContent(String path) { 62 public byte[] getContent(String path) {
61 String filePath = getFilePath(path); 63 String filePath = getFilePath(path);
62 String fileName = FileUtil.getName(filePath); 64 String fileName = FileUtil.getName(filePath);
63 - String dir = StrUtil.removeSuffix(path, fileName); 65 + String dir = StrUtil.removeSuffix(filePath, fileName);
64 ByteArrayOutputStream out = new ByteArrayOutputStream(); 66 ByteArrayOutputStream out = new ByteArrayOutputStream();
65 ftp.download(dir, fileName, out); 67 ftp.download(dir, fileName, out);
66 return out.toByteArray(); 68 return out.toByteArray();
@@ -70,4 +72,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { @@ -70,4 +72,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
70 return config.getBasePath() + path; 72 return config.getBasePath() + path;
71 } 73 }
72 74
73 -} 75 -}
  76 +}
74 \ No newline at end of file 77 \ No newline at end of file