AbstractFtp增加rename方法(issue#IC3PMI@Gitee)

This commit is contained in:
Looly
2025-04-26 11:52:17 +08:00
parent 6d8764eb03
commit 9015c3ea0a
5 changed files with 39 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
* 【core 】 增加分段锁实现`SegmentLock`pr#1330@Gitee
* 【core 】 重载subtractToList方法提供isLinked选项pr#3923@Github
* 【extra 】 `TemplateConfig`增加`setUseCache`方法issue#IC3JRY@Gitee
* 【extra 】 `AbstractFtp`增加`rename`方法issue#IC3PMI@Gitee
### 🐞Bug修复
* 【setting】 修复`Setting`autoLoad可能的加载为空的问题issue#3919@Github

View File

@@ -250,6 +250,15 @@ public abstract class AbstractFtp implements Closeable {
*/
public abstract void recursiveDownloadFolder(String sourcePath, File destDir);
/**
* 重命名文件/目录
*
* @param from 原路径
* @param to 目标路径
* @since 5.8.38
*/
public abstract void rename(String from, String to);
// ---------------------------------------------------------------------------------------------------------------------------------------- Private method start
/**

View File

@@ -726,6 +726,17 @@ public class Ftp extends AbstractFtp {
}
}
@Override
public void rename(String from, String to) {
try {
if (!client.rename(from, to)) {
throw new FtpException("rename [{}] to [{}] fail", from, to);
}
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
/**
* 获取FTPClient客户端对象
*

View File

@@ -647,6 +647,15 @@ public class Sftp extends AbstractFtp {
}
@Override
public void rename(String from, String to) {
try {
getClient().rename(from, to);
} catch (SftpException e) {
throw new JschRuntimeException(e);
}
}
/**
* 获取远程文件
*

View File

@@ -210,6 +210,15 @@ public class SshjSftp extends AbstractFtp {
}
}
@Override
public void rename(String from, String to) {
try {
sftp.rename(from, to);
} catch (IOException e) {
throw new FtpException(e);
}
}
@Override
public void close() {
IoUtil.close(this.session);