mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
避免重复rename函数,增加新单元测试SshjSftpTest,SftpTest用于测试Sftp类
This commit is contained in:
@@ -737,25 +737,6 @@ 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客户端对象
|
||||
*
|
||||
|
@@ -656,23 +656,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程文件
|
||||
*
|
||||
|
@@ -261,23 +261,6 @@ 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);
|
||||
|
@@ -16,18 +16,18 @@ import java.util.List;
|
||||
*/
|
||||
public class SftpTest {
|
||||
|
||||
private SshjSftp sshjSftp;
|
||||
private Sftp sftp;
|
||||
|
||||
@Before
|
||||
@Disabled
|
||||
public void init() {
|
||||
sshjSftp = new SshjSftp("127.0.0.1", 8022, "test", "test", CharsetUtil.CHARSET_UTF_8);
|
||||
sftp = new Sftp("127.0.0.1", 8022, "test", "test", CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void lsTest() {
|
||||
List<String> files = sshjSftp.ls("/");
|
||||
List<String> files = sftp.ls("/");
|
||||
if (files != null && !files.isEmpty()) {
|
||||
files.forEach(System.out::println);
|
||||
}
|
||||
@@ -36,26 +36,26 @@ public class SftpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void downloadTest() {
|
||||
sshjSftp.recursiveDownloadFolder("/temp/20250427/", new File("D:\\temp\\20250430\\20250427\\"));
|
||||
sftp.recursiveDownloadFolder("/temp/20250427/", new File("D:\\temp\\20250430\\20250427\\"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void uploadTest() {
|
||||
sshjSftp.upload("/ftp-2/20250430/", new File("D:\\temp\\20250430\\test.txt"));
|
||||
sftp.upload("/ftp-2/20250430/", new File("D:\\temp\\20250430\\test.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void mkDirTest() {
|
||||
boolean flag = sshjSftp.mkdir("/ftp-2/20250430-1");
|
||||
boolean flag = sftp.mkdir("/ftp-2/20250430-1");
|
||||
System.out.println("是否创建成功: " + flag);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void pwdTest() {
|
||||
String pwd = sshjSftp.pwd();
|
||||
String pwd = sftp.pwd();
|
||||
System.out.println("PWD: " + pwd);
|
||||
}
|
||||
|
||||
@@ -63,19 +63,19 @@ public class SftpTest {
|
||||
@Disabled
|
||||
public void mkDirsTest() {
|
||||
// 在当前目录下批量创建目录
|
||||
sshjSftp.mkDirs("/ftp-2/20250430-2/t1/t2/");
|
||||
sftp.mkDirs("/ftp-2/20250430-2/t1/t2/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void delDirTest() {
|
||||
sshjSftp.delDir("/ftp-2/20250430-2/t1/t2");
|
||||
sftp.delDir("/ftp-2/20250430-2/t1/t2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void cdTest() {
|
||||
System.out.println(sshjSftp.cd("/ftp-2"));
|
||||
System.out.println(sshjSftp.cd("/ftp-4"));
|
||||
System.out.println(sftp.cd("/ftp-2"));
|
||||
System.out.println(sftp.cd("/ftp-4"));
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ class SshjSftpTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
sshjSftp = new SshjSftp("localhost", 22, "test", "test", CharsetUtil.CHARSET_UTF_8);
|
||||
sshjSftp = new SshjSftp("localhost", 8022, "test", "test", CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -31,7 +31,7 @@ class SshjSftpTest {
|
||||
public void lsTest() {
|
||||
List<String> files = sshjSftp.ls("/");
|
||||
if (files != null && !files.isEmpty()) {
|
||||
files.forEach(System.out::print);
|
||||
files.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class SshjSftpTest {
|
||||
|
||||
@Test
|
||||
public void renameTest() {
|
||||
sshjSftp.mkdir("/ftp-1");
|
||||
// sshjSftp.mkdir("/ftp-1");
|
||||
assertTrue(sshjSftp.exist("/ftp-1"));
|
||||
sshjSftp.rename("/ftp-1", "/ftp-2");
|
||||
assertTrue(sshjSftp.exist("/ftp-2"));
|
||||
|
Reference in New Issue
Block a user