mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程文件
|
||||
*
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user