简体   繁体   English

面向com.sshtools.j2ssh.transport.TransportProtocolException的j2ssh插件

[英]Facing com.sshtools.j2ssh.transport.TransportProtocolException for j2ssh plugin

As I come to know that LeeDavidPainter is the author of j2ssh plugin. 我知道LeeDavidPainter是j2ssh插件的作者。 I wanted to ask a question in which I am stuck on. 我想问一个困扰我的问题。 I am trying to connect to a system using the j2ssh plugin with just IP and password. 我正在尝试仅使用IP和密码使用j2ssh插件连接到系统。 I see this stack trace: 我看到此堆栈跟踪:

INFO: Loading key exchange methods
Mar 09, 2016 5:23:05 PM com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory <clinit>
INFO: Loading public key algorithms
Mar 09, 2016 5:23:05 PM com.sshtools.j2ssh.transport.compression.SshCompressionFactory <clinit>
INFO: Loading compression methods
Mar 09, 2016 5:23:05 PM com.sshtools.j2ssh.transport.hmac.SshHmacFactory <clinit>
INFO: Loading message authentication methods
Mar 09, 2016 5:23:05 PM com.sshtools.j2ssh.transport.TransportProtocolCommon startTransportProtocol
INFO: Starting transport protocol
Mar 09, 2016 5:23:05 PM com.sshtools.j2ssh.transport.TransportProtocolCommon run
INFO: Registering transport protocol messages with inputstream
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon negotiateVersion
INFO: Negotiating protocol version
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon negotiateVersion
INFO: Protocol negotiation complete
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon sendMessage
INFO: Sending SSH_MSG_KEX_INIT
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon startBinaryPacketProtocol
INFO: Received SSH_MSG_KEX_INIT
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon beginKeyExchange
INFO: Starting key exchange
Mar 09, 2016 5:23:06 PM com.sshtools.j2ssh.transport.TransportProtocolCommon sendMessage
INFO: Sending SSH_MSG_DISCONNECT
com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete
    at com.sshtools.j2ssh.transport.TransportProtocolClient.onStartTransportProtocol(Unknown Source)
    at com.sshtools.j2ssh.transport.TransportProtocolCommon.startTransportProtocol(Unknown Source)
    at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
    at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
    at checkThat.connect(checkThat.java:34)
    at checkThat.main(checkThat.java:19)

I saw one of his posts in which he said this is out of date and I could use a new plugin by you which is J2SSH Maverick. 我看到他的一篇文章中他说这已经过时了,您可以使用一个新的插件J2SSH Maverick。

But when I used that I see the methods that I am using here are not compatible with the new plugin. 但是当我使用它时,我看到这里使用的方法与新插件不兼容。 SO Do I have to change the methods as well. 所以我也必须改变方法。 I will show my code as well below. 我还将在下面显示我的代码。

import java.io.IOException;
import java.util.List;
import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
import com.sshtools.j2ssh.authentication.KBIAuthenticationClient;
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
import com.sshtools.j2ssh.transport.IgnoreHostKeyVerification;


public class checkThat {


public static void main(String s[])
{
    try {
        connect();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public static void connect() throws Exception {
    try {
        int result =-1;
        String m_sUser= "user";
        String m_sPassword="pswd";

        SshClient ssh = new SshClient();  
        try{
        ssh.connect("1.1.1.1", 22, new IgnoreHostKeyVerification());
        }catch (IOException ie)
        {
            ie.printStackTrace();
        }

        //System.out.println( "Connect successful");


        List authType = ssh.getAvailableAuthMethods(m_sUser);
        if(!authType.isEmpty() && authType.contains("password"))
          {
            //m_logger.severe("FTSSH:Connected to host via password");
            PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
            pwd.setUsername(m_sUser);
            pwd.setPassword(m_sPassword);
            // Authenticate the user
            result = ssh.authenticate(pwd);
          }
        else
          {
            //m_logger.severe("FTSSH:Connected to host via KBI");
            KBIAuthenticationClient kbi = new KBIAuthenticationClient();
            kbi.setUsername(m_sUser);
            /*ASCKBIRequestHandler kbiHandler = new ASCKBIRequestHandler();
            kbiHandler.setPassCode(m_sPassword);
            kbi.setKBIRequestHandler(kbiHandler);*/
            //  Authenticate the user
            result = ssh.authenticate(kbi);
          }

        /* Authenticate.
         * If you get an IOException saying something like
         * "Authentication method password not supported by the server at this stage."
         */
        PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
        pwd.setUsername("user");
        pwd.setPassword("pswd");

         result = ssh.authenticate(pwd);

        if (result != AuthenticationProtocolState.COMPLETE){                
            throw new Exception("Login to  failed");
        } 

        /*session =     ssh.openSessionChannel();
        sor = new SessionOutputReader(session);
        // Request a pseudo terminal, if you do not you may not see the prompt
        session.requestPseudoTerminal("gogrid",80,48, 0 , 0, "");
        // Start the users shell
        session.startShell();*/

    } catch (Exception e) {
        //log.error(e.getMessage(), e);
        System.out.println( e.getMessage());
         e.printStackTrace();
        throw new Exception("Login to  failed");
    }

}
}

So here if I change the .jar file from j2ssh to j2ssh maverick, the methods such as sshClient , ignoreHostKeyVerification , PasswordAuthenticationClient , etc. are not resolved. 因此,在这里,如果将.jar文件从j2ssh更改为j2ssh特立独行,则无法解析sshClientignoreHostKeyVerificationPasswordAuthenticationClient等方法。

What could be the issue? 可能是什么问题?

The J2SSH API and J2SSH Maverick API are different products. J2SSH API和J2SSH Maverick API是不同的产品。 So you cannot expect to use the same source code without refactoring it. 因此,您不能期望在不重构的情况下使用相同的源代码。 I have mentioned in the past that the APIs are similar, they are. 过去我曾提到过,API是相似的。 But being a complete rewrite the Maverick API has improvements/differences that mean you will need to look at the examples provided with it. 但是,作为完整的重写,Maverick API具有改进/差异,这意味着您需要查看其随附的示例。

I recommend you take a look at the PasswordConnect.java example of J2SSH Maverick. 我建议您看一下J2SSH Maverick的PasswordConnect.java示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM