Package org.apache.sshd.client.channel

Examples of org.apache.sshd.client.channel.ChannelShell


        SshClient client = SshClient.setUpDefaultClient();
        client.start();
        ClientSession session = client.connect("localhost", port).await().getSession();
        session.authPassword("smx", "smx").await();
        ChannelShell channel = session.createShellChannel();

        ByteArrayOutputStream sent = new ByteArrayOutputStream();
        PipedOutputStream pipedIn = new PipedOutputStream();
        channel.setIn(new PipedInputStream(pipedIn));
        OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        channel.setOut(out);
        channel.setErr(err);
        channel.open();

        teeOut.write("this is my command\n".getBytes());
        teeOut.flush();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 100; i++) {
            sb.append("0123456789");
        }
        sb.append("\n");

        final AtomicInteger exchanges = new AtomicInteger();
        session.addListener(new SessionListener() {
            public void sessionCreated(Session session) {
            }
            public void sessionEvent(Session sesssion, Event event) {
                if (event == Event.KeyEstablished) {
                    exchanges.incrementAndGet();
                }
            }
            public void sessionClosed(Session session) {
            }
        });
        for (int i = 0; i < 100; i++) {
            teeOut.write(sb.toString().getBytes());
            teeOut.flush();
        }
        teeOut.write("exit\n".getBytes());
        teeOut.flush();

        channel.waitFor(ClientChannel.CLOSED, 0);

        channel.close(false);
        client.stop();

        assertTrue("Expected rekeying", exchanges.get() > 0);
        assertEquals(sent.toByteArray().length, out.toByteArray().length);
        assertArrayEquals(sent.toByteArray(), out.toByteArray());
View Full Code Here


            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
    }

    public ChannelShell createShellChannel() throws Exception {
        ChannelShell channel = new ChannelShell();
        registerChannel(channel);
        return channel;
    }
View Full Code Here

            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
    }

    public ChannelShell createShellChannel() throws IOException {
        ChannelShell channel = new ChannelShell();
        getConnectionService().registerChannel(channel);
        return channel;
    }
View Full Code Here

        SshClient client1 = SshClient.setUpDefaultClient();
        client1.setAgentFactory(localAgentFactory);
        client1.start();
        ClientSession session1 = client1.connect("localhost", port1).await().getSession();
        assertTrue(session1.authAgent("smx").await().isSuccess());
        ChannelShell channel1 = session1.createShellChannel();
        ByteArrayOutputStream sent = new ByteArrayOutputStream();
        PipedOutputStream pipedIn = new TeePipedOutputStream(sent);
        channel1.setIn(new PipedInputStream(pipedIn));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        channel1.setOut(out);
        channel1.setErr(err);
        channel1.setAgentForwarding(true);
        channel1.open().await();

        synchronized (shellFactory.shell) {
            shellFactory.shell.wait();
        }

        SshClient client2 = SshClient.setUpDefaultClient();
        client2.setAgentFactory(agentFactory);
        client2.getProperties().putAll(shellFactory.shell.getEnvironment().getEnv());
        client2.start();
        ClientSession session2 = client2.connect("localhost", port2).await().getSession();
        assertTrue(session2.authAgent("smx").await().isSuccess());
        ChannelShell channel2 = session2.createShellChannel();
        channel2.setIn(shellFactory.shell.getIn());
        channel2.setOut(shellFactory.shell.getOut());
        channel2.setErr(shellFactory.shell.getErr());
        channel2.setAgentForwarding(true);
        channel2.open().await();

        pipedIn.write("foo\n".getBytes());
        pipedIn.flush();

        Thread.sleep(1000);
View Full Code Here

            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
    }

    public ChannelShell createShellChannel() throws Exception {
        ChannelShell channel = new ChannelShell();
        registerChannel(channel);
        return channel;
    }
View Full Code Here

    public ClientChannel createChannel(String type) throws Exception {
        // TODO: use NamedFactory to create channel
        AbstractClientChannel channel;
        if (ClientChannel.CHANNEL_SHELL.equals(type)) {
            channel = new ChannelShell();
        } else if (ClientChannel.CHANNEL_EXEC.equals(type)) {
            channel = new ChannelExec();
        } else {
            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
View Full Code Here

            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
    }

    public ChannelShell createShellChannel() throws Exception {
        ChannelShell channel = new ChannelShell();
        registerChannel(channel);
        return channel;
    }
View Full Code Here

    public ClientChannel createChannel(String type) throws Exception {
        // TODO: use NamedFactory to create channel
        AbstractClientChannel channel;
        if (ClientChannel.CHANNEL_SHELL.equals(type)) {
            channel = new ChannelShell();
        } else if (ClientChannel.CHANNEL_EXEC.equals(type)) {
            channel = new ChannelExec();
        } else {
            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
View Full Code Here

    public ClientChannel createChannel(String type) throws Exception {
        // TODO: use NamedFactory to create channel
        AbstractClientChannel channel;
        if (ClientChannel.CHANNEL_SHELL.equals(type)) {
            channel = new ChannelShell();
        } else if (ClientChannel.CHANNEL_EXEC.equals(type)) {
            channel = new ChannelExec();
        } else {
            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
View Full Code Here

            throw new IllegalArgumentException("Unsupported channel type " + type);
        }
    }

    public ChannelShell createShellChannel() throws Exception {
        ChannelShell channel = new ChannelShell();
        registerChannel(channel);
        return channel;
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.client.channel.ChannelShell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.