mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
FTP接口增加rename方法,改文件/目录名
This commit is contained in:
@@ -250,6 +250,14 @@ public abstract class AbstractFtp implements Closeable {
|
||||
*/
|
||||
public abstract void recursiveDownloadFolder(String sourcePath, File destDir);
|
||||
|
||||
/**
|
||||
* 重命名文件/目录
|
||||
*
|
||||
* @param from 原路径
|
||||
* @param to 目标路径
|
||||
*/
|
||||
public abstract void rename(String from, String to);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------- Private method start
|
||||
|
||||
/**
|
||||
|
@@ -726,6 +726,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客户端对象
|
||||
*
|
||||
@@ -745,4 +764,5 @@ public class Ftp extends AbstractFtp {
|
||||
this.client = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -647,6 +647,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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程文件
|
||||
*
|
||||
|
@@ -88,7 +88,7 @@ public class SshjSftp extends AbstractFtp {
|
||||
* @param config FTP配置
|
||||
* @since 5.3.3
|
||||
*/
|
||||
protected SshjSftp(FtpConfig config) {
|
||||
public SshjSftp(FtpConfig config) {
|
||||
super(config);
|
||||
init();
|
||||
}
|
||||
@@ -210,6 +210,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