add rename

This commit is contained in:
Looly
2025-04-26 11:45:33 +08:00
parent 8b3e6c99c4
commit 05dfc221a5
4 changed files with 38 additions and 0 deletions

View File

@@ -403,6 +403,15 @@ public class CommonsFtp extends AbstractFtp {
return ftpFiles;
}
@Override
public boolean rename(String oldPath, String newPath) {
try {
return this.client.rename(oldPath, newPath);
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@Override
public boolean mkdir(final String dir) throws IORuntimeException {
try {

View File

@@ -127,6 +127,15 @@ public interface Ftp extends Closeable {
*/
List<String> ls(String path);
/**
* 重命名文件
*
* @param oldPath 旧文件名(或路径)
* @param newPath 新文件名(或路径)
* @return 是否重命名成功
*/
boolean rename(String oldPath, String newPath);
/**
* 删除指定目录下的指定文件
*

View File

@@ -328,6 +328,16 @@ public class JschSftp extends AbstractFtp {
return entryList;
}
@Override
public boolean rename(String oldPath, String newPath) {
try {
getClient().rename(oldPath, newPath);
} catch (final SftpException e) {
throw new SshException(e);
}
return true;
}
@Override
public boolean mkdir(final String dir) {
if (isDir(dir)) {

View File

@@ -188,6 +188,16 @@ public class SshjSftp extends AbstractFtp {
return null;
}
@Override
public boolean rename(String oldPath, String newPath) {
try {
sftp.rename(oldPath, newPath);
return containsFile(newPath);
} catch (final IOException e) {
throw new FtpException(e);
}
}
@Override
public boolean delFile(final String path) {
try {