Commit 247b893131895f9b831c248f7d96d7418be5114a
Committed by
Gitee
!156 解决在windows下ftp上传和ftp下载的
Merge pull request !156 from emaisi/feature/1.6.2
Showing
1 changed file
with
7 additions
and
5 deletions
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(), |
| ... | ... | @@ -60,7 +62,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { |
| 60 | 62 | public byte[] getContent(String path) { |
| 61 | 63 | String filePath = getFilePath(path); |
| 62 | 64 | String fileName = FileUtil.getName(filePath); |
| 63 | - String dir = StrUtil.removeSuffix(path, fileName); | |
| 65 | + String dir = StrUtil.removeSuffix(filePath, fileName); | |
| 64 | 66 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 65 | 67 | ftp.download(dir, fileName, out); |
| 66 | 68 | return out.toByteArray(); |
| ... | ... | @@ -70,4 +72,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> { |
| 70 | 72 | return config.getBasePath() + path; |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | 75 | -} |
| 76 | +} | |
| 74 | 77 | \ No newline at end of file | ... | ... |