mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
Merge branch 'feature/1.6.2' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/1.6.2
This commit is contained in:
commit
d8a242629b
@ -27,9 +27,11 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
// 补全风格。例如说 Linux 是 /,Windows 是 \
|
// 把配置的 \ 替换成 /, 如果路径配置 \a\test, 替换成 /a/test, 替换方法已经处理 null 情况
|
||||||
if (!config.getBasePath().endsWith(File.separator)) {
|
config.setBasePath(StrUtil.replace(config.getBasePath(), StrUtil.BACKSLASH, StrUtil.SLASH));
|
||||||
config.setBasePath(config.getBasePath() + File.separator);
|
// ftp的路径是 / 结尾
|
||||||
|
if (!config.getBasePath().endsWith(StrUtil.SLASH)) {
|
||||||
|
config.setBasePath(config.getBasePath() + StrUtil.SLASH);
|
||||||
}
|
}
|
||||||
// 初始化 Ftp 对象
|
// 初始化 Ftp 对象
|
||||||
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
||||||
@ -42,6 +44,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
|||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
String fileName = FileUtil.getName(filePath);
|
String fileName = FileUtil.getName(filePath);
|
||||||
String dir = StrUtil.removeSuffix(filePath, fileName);
|
String dir = StrUtil.removeSuffix(filePath, fileName);
|
||||||
|
ftp.reconnectIfTimeout();
|
||||||
boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
|
boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
||||||
@ -53,6 +56,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
|||||||
@Override
|
@Override
|
||||||
public void delete(String path) {
|
public void delete(String path) {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
|
ftp.reconnectIfTimeout();
|
||||||
ftp.delFile(filePath);
|
ftp.delFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +64,9 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
|||||||
public byte[] getContent(String path) {
|
public byte[] getContent(String path) {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
String fileName = FileUtil.getName(filePath);
|
String fileName = FileUtil.getName(filePath);
|
||||||
String dir = StrUtil.removeSuffix(path, fileName);
|
String dir = StrUtil.removeSuffix(filePath, fileName);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ftp.reconnectIfTimeout();
|
||||||
ftp.download(dir, fileName, out);
|
ftp.download(dir, fileName, out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user