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
在线等解决方案,谢谢

相关文章
|
6月前
|
存储 安全 Linux
在 Linux 上保护 SSH 服务器连接的 8 种方法
本文主要介绍了8种提高SSH协议安全性的方法,这些在实际工作中其实是都会有所用到的,比如服务器基线啥的,希望大家一起努力维护好自己的服务器。另注:本文为转载,版权为原作者所有https://www.linuxmi.com/secure-ssh-connections-linux.html,侵删。
|
安全 网络安全 C++
基于Windows下VSCode安装及安装相关插件通过SSH协议远程连接服务器详细方法(一)
基于Windows下VSCode安装及安装相关插件通过SSH协议远程连接服务器详细方法
349 0
基于Windows下VSCode安装及安装相关插件通过SSH协议远程连接服务器详细方法(一)
|
Ubuntu Linux 网络安全
通过 SSH 在远程和本地系统之间传输文件的 4 种方法
通过 SSH 在远程和本地系统之间传输文件的 4 种方法
4643 0
通过 SSH 在远程和本地系统之间传输文件的 4 种方法
|
2月前
|
Ubuntu Linux 网络安全
MobaXterm的是有用方法---集串口,SSH远程登录和FTP传输三合一工具
MobaXterm的是有用方法---集串口,SSH远程登录和FTP传输三合一工具
72 3
|
8月前
|
安全 网络协议 网络安全
【【安全知识】SSH远程登录方法详解】
SSH(Secure Shell)是一种安全的网络协议,用于远程登录和安全数据传输。在本文中,我们将详细介绍如何使用SSH进行远程登录。
752 0
|
6月前
|
Linux 网络安全 数据安全/隐私保护
Linux下ssh远程主机报错:ssh_exchange_identification: read: Connection 解决
Linux下ssh远程主机报错:ssh_exchange_identification: read: Connection 解决
|
8月前
|
iOS开发
iOS 逆向编程(Error)ssh_exchange_identification: read: Connection reset by peer
iOS 逆向编程(Error)ssh_exchange_identification: read: Connection reset by peer
86 0
|
10月前
|
安全 网络安全 数据安全/隐私保护
SSH 穿越多个跳板机的连接方法
SSH 穿越多个跳板机的连接方法
391 0
|
10月前
|
jenkins 持续交付 网络安全
2. 成功解决 BUG:Exception when publishing, ...[Failed to connect and initialize SSH connection...
SSH: Connecting from host [WIN-...] SSH: Connecting with configuration [192.168....] ... ERROR: Exception when publishing, exception message [Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [192.168....]. Message [java.net.ConnectException: Connection
1045 0
|
Linux Shell 网络安全
【Linux】——在Xshell输入ssh root@公网ip进行远程连接Linux失败,显示(port 22): Connection failed的完美解决方法
【Linux】——在Xshell输入ssh root@公网ip进行远程连接Linux失败,显示(port 22): Connection failed的完美解决方法
625 0