From 2b777c3841fcd121dd984404abeafab2bf3b118a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8E=89=E5=86=9B?= Date: Wed, 30 Apr 2025 16:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8Drename?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95SshjSftpTest=EF=BC=8CSftpTest?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95Sftp=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/hutool/extra/ftp/Ftp.java | 19 ---------------- .../main/java/cn/hutool/extra/ssh/Sftp.java | 17 -------------- .../java/cn/hutool/extra/ssh/SshjSftp.java | 17 -------------- .../java/cn/hutool/extra/ssh/SftpTest.java | 22 +++++++++---------- .../cn/hutool/extra/ssh/SshjSftpTest.java | 6 ++--- 5 files changed, 14 insertions(+), 67 deletions(-) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java index 0ca46df71..ee4aab39e 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java @@ -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客户端对象 * diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java index aee22386a..9f47866fd 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java @@ -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); - } - } - /** * 获取远程文件 * diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/SshjSftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/SshjSftp.java index 4d8b0c040..227f4e421 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/SshjSftp.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ssh/SshjSftp.java @@ -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); diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java index 81f0669ae..39eaeca3d 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java @@ -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 files = sshjSftp.ls("/"); + List 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")); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SshjSftpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SshjSftpTest.java index 6c5c8ef63..29ff13358 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SshjSftpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SshjSftpTest.java @@ -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 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"));