From 6e2e137b91494e6861f282e04e8e4e829de21b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8E=89=E5=86=9B?= Date: Wed, 30 Apr 2025 15:28:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/extra/ssh/SftpTest.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) 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 e7429b873..81f0669ae 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 @@ -2,8 +2,8 @@ package cn.hutool.extra.ssh; import cn.hutool.core.util.CharsetUtil; import org.junit.Before; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; import java.io.File; import java.util.List; @@ -21,7 +21,7 @@ public class SftpTest { @Before @Disabled public void init() { - sshjSftp = new SshjSftp("ip", 22, "test", "test", CharsetUtil.CHARSET_UTF_8); + sshjSftp = new SshjSftp("127.0.0.1", 8022, "test", "test", CharsetUtil.CHARSET_UTF_8); } @Test @@ -29,39 +29,53 @@ public class SftpTest { public void lsTest() { List files = sshjSftp.ls("/"); if (files != null && !files.isEmpty()) { - files.forEach(System.out::print); + files.forEach(System.out::println); } } @Test @Disabled public void downloadTest() { - sshjSftp.recursiveDownloadFolder("/home/test/temp", new File("C:\\Users\\akwangl\\Downloads\\temp")); + sshjSftp.recursiveDownloadFolder("/temp/20250427/", new File("D:\\temp\\20250430\\20250427\\")); } @Test @Disabled public void uploadTest() { - sshjSftp.upload("/home/test/temp/", new File("C:\\Users\\akwangl\\Downloads\\temp\\辽宁_20190718_104324.CIME")); + sshjSftp.upload("/ftp-2/20250430/", new File("D:\\temp\\20250430\\test.txt")); } @Test @Disabled public void mkDirTest() { - boolean flag = sshjSftp.mkdir("/home/test/temp"); + boolean flag = sshjSftp.mkdir("/ftp-2/20250430-1"); System.out.println("是否创建成功: " + flag); } + @Test + @Disabled + public void pwdTest() { + String pwd = sshjSftp.pwd(); + System.out.println("PWD: " + pwd); + } + @Test @Disabled public void mkDirsTest() { // 在当前目录下批量创建目录 - sshjSftp.mkDirs("/home/test/temp"); + sshjSftp.mkDirs("/ftp-2/20250430-2/t1/t2/"); } @Test @Disabled public void delDirTest() { - sshjSftp.delDir("/home/test/temp"); + sshjSftp.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")); } }