Commit 247b893131895f9b831c248f7d96d7418be5114a

Authored by 芋道源码
Committed by Gitee
2 parents 60f918da b5f97f69

!156 解决在windows下ftp上传和ftp下载的

Merge pull request !156 from emaisi/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,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