Merge remote-tracking branch 'origin/feature/ftp-rename' into v5-dev

# Conflicts:
#	hutool-extra/src/main/java/cn/hutool/extra/ftp/AbstractFtp.java
#	hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java
This commit is contained in:
厉军
2025-04-30 15:29:45 +08:00
5 changed files with 153 additions and 1 deletions

View File

@@ -737,6 +737,25 @@ public class Ftp extends AbstractFtp {
}
}
/**
* 重命名文件/目录
*
* @param from 原路径
* @param to 目标路径
*
* @throws FtpException FTP异常
*/
@Override
public void rename(String from, String to) throws FtpException {
try {
if (!client.rename(from, to)) {
throw new FtpException("rename [{}] to [{}] fail", from, to);
}
} catch (IOException e) {
throw new FtpException(e);
}
}
/**
* 获取FTPClient客户端对象
*
@@ -756,4 +775,5 @@ public class Ftp extends AbstractFtp {
this.client = null;
}
}
}

View File

@@ -656,6 +656,23 @@ public class Sftp extends AbstractFtp {
}
}
/**
* 重命名文件/目录
*
* @param from 原路径
* @param to 目标路径
*
* @throws JschRuntimeException Jsch异常
*/
@Override
public void rename(String from, String to) throws JschRuntimeException {
try {
getClient().rename(from, to);
} catch (SftpException e) {
throw new JschRuntimeException(e);
}
}
/**
* 获取远程文件
*

View File

@@ -90,7 +90,7 @@ public class SshjSftp extends AbstractFtp {
* @param config FTP配置
* @since 5.3.3
*/
protected SshjSftp(FtpConfig config) {
public SshjSftp(FtpConfig config) {
super(config);
init();
}
@@ -261,6 +261,23 @@ public class SshjSftp extends AbstractFtp {
}
}
/**
* 重命名文件/目录
*
* @param from 原路径
* @param to 目标路径
*
* @throws FtpException FTP异常
*/
@Override
public void rename(String from, String to) throws FtpException {
try {
sftp.rename(from, to);
} catch (IOException e) {
throw new FtpException(e);
}
}
@Override
public void close() {
IoUtil.close(this.session);