ssh2 Connection .connect()方法抛出连接过早关闭异常

简介: ssh2 Connection .connect()方法抛出连接过早关闭异常
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
 
public class   manager{
 
    private final String  chineseToFirstLetter = xx;
    private final String hostName = "xx.xx.xx.xx";
    private final int port = xxxx;
    private final String userName = "xxxx";
    private final String password = "xxxx";
    
    //另一个服务器执行sql文件方法
    scriptSql.getConn(chineseToFirstLetter);
    Connection conn = new Connection(hostName,port);
    Session sess = null;
    try {
        conn.connect();
        boolean isAuthenticated = conn.authenticateWithPassword(userName,
                                        password);
        if (isAuthenticated == false) {
            return BaseDtoHttp.ofError(530,"连接不上服务器!");
        }
        sess = conn.openSession();
        sess.execCommand("sh D:/test/sql.sh"+ chineseToFirstLetter);
        InputStream stdout = new StreamGobbler(sess.getStdout());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                System.out.println(line);
            }
     } catch (IOException e) {
         return BaseDtoHttp.ofError(530,"创建失败!");
     } finally {
         sess.close();
         conn.close();
     }
}

f85c82ea4b57f02ea22582f2553401f.jpg
在线等解决方案,谢谢

相关文章
|
1月前
|
网络安全 数据安全/隐私保护 开发者
诊断并修复SSH连接Github时遇到的"connection closed"错误。
解决"connection closed"错误往往是一个排除法的过程。需要从基础的网络检查做起,逐步过渡到深入的配置和服务端日志审查。每一步都应当仔细验证,确保不遗漏可能导致连接问题的任何细节。在执行以上步骤后,大多数SSH连接问题可以得到解决。如果所有步骤都未能解决问题,可能需要寻求更专业的技术支持,或者在GitHub社区寻找是否有其他开发者遇到并解决了类似的问题。
250 0
|
1月前
|
安全 网络安全 数据安全/隐私保护
解决SSH测试连接GitHub时出现“connection closed by remote host”的问题。
然后使用 `ssh -T git@ssh.github.com`来测试连接。
237 0
|
5月前
|
安全 Linux 网络安全
在Linux(CentOS和AWS)上安装更新的git2的方法并配置github-ssh
经过以上这些步骤,你现在就能在GitHub上顺利往返,如同海洋中的航海者自由驰骋。欢迎你加入码农的世界,享受这编程的乐趣吧!
199 10
|
9月前
|
监控 Ubuntu 安全
debian或Ubuntu中开启ssh允许root远程ssh登录的方法
在Debian或Ubuntu系统中启用root用户的SSH远程登录需要编辑SSH配置文件、设置root密码并重启SSH服务。虽然这可以在某些情况下提供便利,但必须注意安全性,通过使用强密码、限制IP访问、使用SSH密钥认证等方法来保护服务器的安全。
3750 5
|
9月前
|
运维 网络安全
解决ssh: connect to host IP port 22: Connection timed out报错(scp传文件指定端口)
通过这些步骤和方法,您可以有效解决“ssh: connect to host IP port 22: Connection timed out”问题,并顺利使用 `scp`命令传输文件。
8983 7
|
9月前
|
网络协议 Ubuntu Linux
解决ssh: connect to host IP port 22: Connection timed out报错(scp传文件指定端口)
解决 `ssh: connect to host IP port 22: Connection timed out` 报错涉及检查 SSH 服务状态、防火墙配置、网络连通性和主机名解析等多个方面。通过逐步排查上述问题,并在 `scp` 命令中正确指定端口,可以有效解决连接超时的问题,确保文件传输的顺利进行。希望本文提供的解决方案能帮助您快速定位并解决该错误。
2175 3
|
10月前
|
监控 Ubuntu Linux
使用VSCode通过SSH远程登录阿里云Linux服务器异常崩溃
通过 VSCode 的 Remote - SSH 插件远程连接阿里云 Ubuntu 22 服务器时,会因高 CPU 使用率导致连接断开。经排查发现,VSCode 连接根目录 ".." 时会频繁调用"rg"(ripgrep)进行文件搜索,导致 CPU 负载过高。解决方法是将连接目录改为"root"(或其他具体的路径),避免不必要的文件检索,从而恢复正常连接。
|
网络协议 Shell 网络安全
ssh: connect to host github.com port 22: Connection refused
本文讨论了在使用Git命令操作GitHub时遇到的"ssh: connect to host github.com port 22: Connection refused"错误,分析了可能的原因,并提供了使用443端口或https协议作为解决方案,最终确定问题是由于DNS解析错误导致,通过修改hosts文件解决。
ssh: connect to host github.com port 22: Connection refused
|
网络安全 开发工具 git
【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效
【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效
4913 1
|
存储 安全 Linux
说到Linux安全,SSH限制IP登录绕不开这3种方法!
说到Linux安全,SSH限制IP登录绕不开这3种方法!
600 0