首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >面向j2ssh插件的com.sshtools.j2ssh.transport.TransportProtocolException

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

Stack Overflow用户
提问于 2016-03-09 20:24:32
回答 1查看 2.4K关注 0票数 0

我看到了这个堆栈跟踪:

代码语言:javascript
复制
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)

我看过他的一个帖子,他说这已经过时了,我可以使用你的一个新插件,那就是J2SSH Maverick。

但是当我使用它时,我发现我在这里使用的方法与新的插件不兼容。我将在下面展示我的代码。

代码语言:javascript
复制
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");
    }

}
}

因此,如果我在这里将.jar文件从j2ssh更改为j2ssh maverick,则无法解析sshClientignoreHostKeyVerificationPasswordAuthenticationClient等方法。

可能的问题是什么?

EN

回答 1

Stack Overflow用户

发布于 2016-03-10 17:53:49

J2SSH接口和J2SSH Maverick接口是不同的产品。因此,您不能期望在不重构的情况下使用相同的源代码。我在过去提到过API是相似的,它们是相似的。但是作为一次完全的重写,Maverick API有一些改进/不同之处,这意味着您需要查看随其提供的示例。

我建议您看看J2SSH Maverick的PasswordConnect.java示例。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35891540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档