apache-camel - Camel SFTP连接jcraft jsch异常

标签 apache-camel jsch camel-ftp

我使用的是camel版本2.13.1和camel-ftp版本2.13.1。我正在尝试通过 Camel 路由连接到 sftp 服务器。我收到一些与 jCraft Jsch 异常相关的错误,如下所示。

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot connect to sftp://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="10657e717d7550637562667562717474627563633e737f7d" rel="noreferrer noopener nofollow">[email protected]</a>:22
    at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:143)
    at org.apache.camel.component.file.remote.RemoteFileConsumer.connectIfNecessary(RemoteFileConsumer.java:154)
    at org.apache.camel.component.file.remote.RemoteFileConsumer.recoverableConnectIfNecessary(RemoteFileConsumer.java:145)
    at org.apache.camel.component.file.remote.RemoteFileConsumer.prePollCheck(RemoteFileConsumer.java:55)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:106)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: com.jcraft.jsch.JSchException: Algorithm negotiation fail
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:582)
    at com.jcraft.jsch.Session.connect(Session.java:320)
    at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:115)
    ... 14 more

最佳答案

从异常消息来看,客户端和SSH服务器之间似乎没有共享 key 交换(KEX)算法。您可以在尝试连接之前通过启用 JSch 中的日志记录来验证这一点:

JSch.setLogger(new Logger() {
    @Override
    public boolean isEnabled(int i) {
        return true;
    }
    @Override
    public void log(int i, String string) {
        System.out.println(string);
    }
};

这将分别输出服务器和客户端支持的 KEX 列表。例如:

kex: server: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

我希望您会看到服务器列出的 KEX 算法都不在客户端列表中。在此基础上,您可以在服务器上启用其他 KEX 算法(前提是您有权访问它),或者在您的客户端应用程序上启用其他 KEX 算法。有关更多信息,另请参阅this page .

如果您无法对服务器进行更改,您可以通过以下两种方式之一添加对其他 KEX 算法的支持:

  1. 将 JSch 升级到最新版本 (0.1.52) 以自动启用对 sha256 的支持。
  2. 如果您无法使用 0.1.51,您可以通过编程方式启用 sha256:

    JSch shell = new JSch();
    Properties config = new Properties();
    config.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
    config.put("StrictHostKeyChecking", "no");
    

然后创建 session 并设置配置:

Session session = ...
session.setConfig(config);

更新: 在这种情况下,事实证明它不是丢失的算法,而是丢失的密码。服务器仅支持 aes256-cbc 密码,默认情况下 Oracle 的 JVM 不支持该密码。不过可以直接从Oracle下载.

关于apache-camel - Camel SFTP连接jcraft jsch异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30033534/

相关文章:

java - 同一路线构建器中不同路线上的 Camel Exchange

java - Camel 测试 - java.lang.IllegalArgumentException : defaultEndpoint must be specified

java - 如何在 SftpProgressMonitor 实例中使用现有的 JProgressBar?

java - 如何将字节或流写入 Apache Camel FTP 以传输文件

java - 如何使用Maven创建Camel项目?

java - Apache Camel Http 和 SSL

java - sudo 登录后使用 Java JSch 程序执行多个 bash 命令

java - 如何使用带有 JSch 库的代理传输文件

java - Apache Camel : Download Multiple Files at once using SFTP component

java - Apache Camel 从 SFTP 下载一些文件不完整