【发布时间】:2023-11-08 18:56:01
【问题描述】:
我正在尝试使用 j2ssh 将文件从我的应用程序 SCP 到服务器。远程服务器正在运行 TECTIA。
从命令行(部署我的应用程序的 Solaris 机器)使用我们交换的密钥对,scp 可以正常工作。
在我的应用程序中,j2ssh 无法建立连接,抛出异常:
Caused by: com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete
来自 j2ssh 的调试日志显示如下:
com.sshtools.j2ssh.transport.TransportProtocolCommon.beginKeyExchange(Unknown Source) | Starting key exchange
com.sshtools.j2ssh.transport.TransportProtocolCommon.determineAlgorithm(Unknown Source) | Determine Algorithm
com.sshtools.j2ssh.transport.TransportProtocolCommon.determineAlgorithm(Unknown Source) | Client Algorithms: [diffie-hellman-group1-sha1]
com.sshtools.j2ssh.transport.TransportProtocolCommon.determineAlgorithm(Unknown Source) | Server Algorithms: [diffie-hellman-group14-sha1, diffie-hellman-group-exchange-sha1]
com.sshtools.j2ssh.transport.TransportProtocolCommon.sendMessage(Unknown Source) | Sending SSH_MSG_DISCONNECT
com.sshtools.j2ssh.transport.TransportProtocolCommon.run(Unknown Source) | The Transport Protocol has been stopped
从上面我可以看到我的应用程序和服务器之间的密钥交换没有匹配算法(调试实际上表明这个问题的根源是AlgorithmNotAgreedException,当没有服务器和客户端算法匹配时,我知道这是根本原因)。
如何向 j2ssh 添加新算法以便它可以找到匹配项? j2ssh 文档非常少。
【问题讨论】:
-
如果您使用 Runtime 的 exec 和 scp,这似乎会容易得多。
-
我同意你和@Jeremy*s 的观点,文件传输的不同实现可能是这里的“最佳”解决方案,但此时它不是一个选项。这是一个特定的用例,恰好打破了我们进行 SFTP 传输的方式。我现在不能重写这部分。现在我受 j2ssh 的约束,直到我有时间重写它(看看你的 Apache VFS)