mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
AbstractFtp
增加rename
方法(issue#IC3PMI@Gitee)
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
||||
/**
|
||||
|
@@ -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客户端对象
|
||||
*
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程文件
|
||||
*
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user