From fc4a71200a2398c44ab92e8982ddd82b4ff4a89d Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 12 May 2025 12:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3`SshjSftp`=E5=9C=A8SftpSubsys?= =?UTF-8?q?tem=E6=9C=8D=E5=8A=A1=E6=97=B6=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=88pr#1338@Gitee=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../java/cn/hutool/extra/ssh/SshjSftp.java | 44 +++++++++---------- .../java/cn/hutool/extra/ftp/FtpTest.java | 1 + .../cn/hutool/extra/ssh/SshjSftpTest.java | 3 ++ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e31fe96f..4a37f0636 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ ### 🐞Bug修复 * 【setting】 修复`Setting`autoLoad可能的加载为空的问题(issue#3919@Github) * 【db 】 修复某些数据库的getParameterMetaData会返回NULL,导致空指针的问题。(pr#3936@Github) +* 【extra 】 修正`SshjSftp`在SftpSubsystem服务时报错问题(pr#1338@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.37(2025-03-31) 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 227f4e421..c0887e2aa 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 @@ -128,28 +128,6 @@ public class SshjSftp extends AbstractFtp { return this; } - private String getPath(String path) { - if (StrUtil.isBlank(this.workingDir)) { - try { - this.workingDir = sftp.canonicalize(""); - } catch (IOException e) { - throw new FtpException(e); - } - } - - if (StrUtil.isBlank(path)) { - return this.workingDir; - } - - // 如果是绝对路径,则返回 - if (StrUtil.startWith(path, StrUtil.SLASH)) { - return path; - } else { - String tmp = StrUtil.removeSuffix(this.workingDir, StrUtil.SLASH); - return StrUtil.format("{}/{}", tmp, path); - } - } - /** * 改变目录,注意目前不支持.. * @param directory directory @@ -327,4 +305,26 @@ public class SshjSftp extends AbstractFtp { } return session; } + + private String getPath(String path) { + if (StrUtil.isBlank(this.workingDir)) { + try { + this.workingDir = sftp.canonicalize(""); + } catch (IOException e) { + throw new FtpException(e); + } + } + + if (StrUtil.isBlank(path)) { + return this.workingDir; + } + + // 如果是绝对路径,则返回 + if (StrUtil.startWith(path, StrUtil.SLASH)) { + return path; + } else { + String tmp = StrUtil.removeSuffix(this.workingDir, StrUtil.SLASH); + return StrUtil.format("{}/{}", tmp, path); + } + } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java index 84692a4a1..e73b6624f 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java @@ -175,6 +175,7 @@ public class FtpTest { } @Test + @Disabled public void renameTest() { final Ftp ftp = new Ftp("localhost", 21, "test", "test"); 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 29ff13358..3c9310e12 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 @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * @author youyongkun * @since 5.7.18 */ +@Disabled class SshjSftpTest { private static SshjSftp sshjSftp; @@ -68,6 +69,7 @@ class SshjSftpTest { } @Test + @Disabled public void pwdTest() { // mkDirsTest(); sshjSftp.cd("/ftp"); @@ -77,6 +79,7 @@ class SshjSftpTest { } @Test + @Disabled public void renameTest() { // sshjSftp.mkdir("/ftp-1"); assertTrue(sshjSftp.exist("/ftp-1"));