- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当使用 jsch 版本 0.1.51 连接到远程主机时,我们偶尔会在 ChannelExec
上调用 Channel.connect()
时遇到以下异常。
com.jcraft.jsch.JSchException: channel is not opened.
at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765)
at com.jcraft.jsch.Channel.connect(Channel.java:151)
at com.jcraft.jsch.Channel.connect(Channel.java:145)
创建 session 后我们使用的代码是:
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand("echo hello");
channel.connect(); // Error here
Channel.connect()
调用通常会在 100 毫秒内返回,但是当发生此错误时,调用会在抛出异常之前挂起超过 20 秒。
最佳答案
异常消息有点误导。当等待来自服务器的 SSH_MSG_CHANNEL_OPEN_CONFIRMATION
消息超时时,可能会发生该错误。 jsch(版本 0.1.51)中的默认超时为 20 秒。我认为还有其他情况会发生相同的错误,但我没有进一步调查。
虽然超时的原因可能有很多,但我们已经看到它是由 OpenSSH 中的 sshd 中的反向 DNS 查找偶尔花费很长时间引起的。
可以通过设置
禁用来自 sshd 的 DNS 查找来解决这个问题UseDNS no
在您的 sshd_config 中(通常是 /etc/ssh/sshd_config
)。根据 Gilles 在 this 中所写,这通常是安全的线程。
另一种选择是增加连接 channel 时的超时时间。 Channel.connect
接受超时参数(毫秒),例如channel.connect(60000)
。如果您不控制要连接的服务器,这会很有用。
关于java - com.jcraft.jsch.JSchException : channel is not opened when opening a channel in jsch 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33895500/
我正在尝试使用 Jsch 在 Java 中建立 SSH 连接。我已将“StrictHostKeyChecking”设置为"is"。据我了解,必须事先获取服务器的主机 key 并将其存储在主机 key
我目前在尝试使用 JSch 通过 ssh 进入盒子时遇到此问题。我已经使用 Cygwin 测试了连接,它可以无缝连接。我已生成 key 对并将公钥放置在远程服务器上的 authorized_keys
我正在尝试从 Java 脚本连接到我的 SFTP 服务器。我正在使用 JSch lib 来实现我的目的。用户名、密码和主机名正确,但我收到一条:身份验证失败错误。 我还尝试在 session.conn
我正在尝试使用 JSch (0.1.44-1) 通过 ssh 连接到远程 sftp 服务器,但在 session.connect(); 期间,我收到此异常: com.jcraft.jsch.JSchE
我正在尝试使用 JSch通过 ssh 连接到我的计算机,然后运行命令。 但是,当我运行代码时,我从未连接到计算机。和以下错误: I/System.out: com.jcraft.jsch.JSchEx
我在 RHEl 6 上使用 Jsch 0.1.51 和 Jdk 1.7_51。在与远程机器进行 session 时出现异常: com.jcraft.jsch.JSchException: Packet
我正在尝试使用 JSch (0.1.44-1) 通过 ssh 连接到远程 sftp 服务器,但在 session.connect(); 期间我收到此异常: com.jcraft.jsch.JSchEx
我不确定我的问题是否存在于 Spring Integration 或 JCraft 的 Jsch 中。我在服务器上有一个应用程序,它使用 SFTP 和 session 池接收文件并将它们放置在另一台服
我正在尝试编写一个 Ant 脚本来通过端口隧道检索 URL。 当我使用密码时效果很好(为保护隐私而使用的名称 xxxx):
我最近将我的云服务器操作系统从 Ubuntu 20.04 更改为 22.04。之后,远程上传 jar 任务在使用 org.hidetake.ssh 进行 gradle 构建期间失败并显示以下消息。 c
我最近将我的云服务器操作系统从 Ubuntu 20.04 更改为 22.04。之后,远程上传 jar 任务在使用 org.hidetake.ssh 进行 gradle 构建期间失败并显示以下消息。 c
我已经编写了一个 ant 脚本来复制本地 tomcat 服务器(在根目录中)上的文件,如下所示: 我的机器上有 openSSH。我不太清
我使用以下代码通过 Windows 在 Linux 上执行命令: JSch jsch=new JSch(); Session session=jsch.getSession(user,
要求是从一台服务器ssh到多台服务器并执行一个命令。 当我这样做时,我经常(但并非总是)在尝试从一台服务器 ssh 到另一台服务器时收到此异常。这可能是什么原因,如何解决?任何帮助都可能很棒。提前致谢
我正在尝试 https://github.com/spring-projects/spring-integration-samples/tree/master/basic/sftp 给出的代码,当我在
当我从本地磁盘上传文件到远程服务器时,出现了这样的异常:com.jcraft.jsch.JSchException: 验证失败 在 org.apache.tools.ant.taskdefs.opti
在尝试将文件上传到我们的服务器时,我收到以下异常 com.jcraft.jsch.JSchException: Auth fail at com.jcraft.jsch.Ses
尝试使用 ssh key 身份验证连接到主机。下面是我的代码: package com.mkyong.common; import com.jcraft.jsch.Channel; import co
我正在尝试从客户端计算机连接到 sftp 服务器。但是 com.jcraft.jsch.JSchException: Algorithm negotiation fail 我遇到了这种错误。 com.
我知道有重复的 >>> 从副本复制 >>>只要您的本地计算机有一个运行的 SSH 服务器 .<到那时会坚持使用JSch.... 顺便说一句,我试试 https://serverfault.com/qu
我是一名优秀的程序员,十分优秀!