org. apache .sshd.common.SshException: DefaultOpenFuture - APACHE MINA для связи SFTP - PullRequest
0 голосов
/ 12 марта 2020

Я получаю следующее исключение:

org.apache.sshd.common.SshException: DefaultOpenFuture[ChannelSubsystem[id=0, recipient=-1]-
        ClientSessionImpl[app6204@denad534.us.oracle.com/10.88.224.99:22][sftp]]: Failed to get operation result within specified timeout: 15000    
at org.apache.sshd.common.future.AbstractSshFuture.formatExceptionMessage(AbstractSshFuture.java:187)
at org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:112)
at org.apache.sshd.client.future.DefaultOpenFuture.verify(DefaultOpenFuture.java:39)
at org.apache.sshd.client.future.DefaultOpenFuture.verify(DefaultOpenFuture.java:32)
at org.apache.sshd.client.subsystem.sftp.impl.DefaultSftpClient.<init>(DefaultSftpClient.java:97)
at org.apache.sshd.client.subsystem.sftp.impl.DefaultSftpClientFactory.createDefaultSftpClient(DefaultSftpClientFactory.java:67)
at org.apache.sshd.client.subsystem.sftp.impl.DefaultSftpClientFactory.createSftpClient(DefaultSftpClientFactory.java:47)
at org.apache.sshd.client.subsystem.sftp.SftpClientFactory.createSftpClient(SftpClientFactory.java:46)
at SSHClientExample.main(SSHClientExample.java:76)

Код:

   public static void main(String[] args){
    SshClient client = SshClient.setUpDefaultClient();

    client.start();
    try {
       // DefaultOpenFuture defaultOpenFuture = new DefaultOpenFuture();
        ConnectFuture future = client.connect("user", "Host", 22);
        //ClientFactoryManager clientFactoryManager = client.
        client.open();

        client.start();
        client.addPasswordIdentity("PWD");
        client.setClientIdentityLoader(ClientIdentityLoader.DEFAULT);
        client.setHostConfigEntryResolver(HostConfigEntryResolver.EMPTY);

        ServerKeyVerifier serverKeyVerifier = AcceptAllServerKeyVerifier.INSTANCE;
        client.setServerKeyVerifier(serverKeyVerifier);
        SessionFactory sessionFactory = client.getSessionFactory();
        ClientFactoryManager factoryManager =sessionFactory.getFactoryManager();

        //.verify is necessary to get session
        ClientSession clientSession = future.verify(100L,TimeUnit.SECONDS).getSession();
       // ClientChannel clientChannel = clientSession.createChannel("exec");
        future.setSession(clientSession);
                //KeyPair keyPair =  new KeyPair(PublicKey.serialVersionUID);
        //clientSession.addPublicKeyIdentity();
        clientSession.setAuthenticated();
        System.out.println(future.isConnected());
        System.out.println(clientSession);
        SftpClientFactory sftpFactory = SftpClientFactory.instance();
        //SFTP Version
        SftpVersionSelector selector = SftpVersionSelector.fixedVersionSelector(6);
        //SFTP Client
       // clientSession.createChannel("FTP");
        System.out.println("Client session opened?"+clientSession.isOpen());
        System.out.println("Client is opened?"+client.isOpen());
        clientSession.addPasswordIdentity("PWD");
        //SftpClient sftpClient = sftpFactory.createSftpClient(clientSession, selector);
        //System.out.println(sftpClient.open(" /slot/dummy/appmgr/location").getPath());
        System.out.println(clientSession.getClientVersion());
        //System.out.println(clientSession.createSubsystemChannel("SFTP").getSubsystem().getBytes());
        DefaultSftpClientFactory defaultSftpClientFactory = new DefaultSftpClientFactory();
        clientSession.addPublicKeyIdentity(KeyPairGeneratorMethod());
        client.addPublicKeyIdentity(KeyPairGeneratorMethod());
        //SftpClient sftp = defaultSftpClientFactory.createSftpClient(clientSession);
        SftpClient sftp = defaultSftpClientFactory.createSftpClient(clientSession);
         //= DefaultSftpClientFactory.INSTANCE.createSftpClient(clientSession);
        //SftpClient sftp = new DefaultSftpClient(clientSession);
        // SimpleSftpClientImpl sftp = new SimpleSftpClientImpl();
        ClientChannel channel = clientSession.createSubsystemChannel(SftpConstants.SFTP_SUBSYSTEM_NAME);
        System.out.println(channel.getSession().isAuthenticated());
        //System.out.println(sftp.open(" /slot/dummy/appmgr/location").getPath());            //client.close();

    }

    catch (SshException e){
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        //TODO
    }

    //client.stop();
}

1 Ответ

0 голосов
/ 13 марта 2020

Мне удалось избавиться от этой ошибки с помощью следующей строки.

clientSession.auth (). Verify ();

...