0

LeeDavidPainter が j2ssh プラグインの作成者であることを知りました。行き詰まっている質問をしたかったのです。IP とパスワードだけで j2ssh プラグインを使用してシステムに接続しようとしています。次のスタック トレースが表示されます。

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 という新しいプラグインを使用できると彼が言った彼の投稿の 1 つを見ました。

しかし、それを使用すると、ここで使用しているメソッドが新しいプラグインと互換性がないことがわかります。SO メソッドも変更する必要がありますか。私のコードも以下に示します。

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、 などのメソッドが解決されません。

問題は何ですか?

4

1 に答える 1

1

J2SSH API とJ2SSH Maverick API は別の製品です。そのため、リファクタリングせずに同じソース コードを使用することは期待できません。過去に、API は似ていると述べましたが、それらは似ています。しかし、Maverick API は完全に書き直されているため、改善点や相違点があるため、提供されている例を確認する必要があります。

J2SSH MaverickのPasswordConnect.javaの例を参照することをお勧めします。

于 2016-03-10T09:53:48.730 に答える