Package org.apache.sshd.client.channel

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


        registerChannel(channel);
        return channel;
    }

    public ChannelExec createExecChannel(String command) throws IOException {
        ChannelExec channel = new ChannelExec(command);
        registerChannel(channel);
        return channel;
    }
View Full Code Here


        getConnectionService().registerChannel(channel);
        return channel;
    }

    public ChannelExec createExecChannel(String command) throws IOException {
        ChannelExec channel = new ChannelExec(command);
        getConnectionService().registerChannel(channel);
        return channel;
    }
View Full Code Here

            session.auth().verify();

        }

        public Process exec(String commandName, int timeout) throws IOException {
            final ChannelExec channel = session.createExecChannel(commandName);
            channel.open().verify();
            return new Process() {
                @Override
                public OutputStream getOutputStream() {
                    return channel.getInvertedIn();
                }

                @Override
                public InputStream getInputStream() {
                    return channel.getInvertedOut();
                }

                @Override
                public InputStream getErrorStream() {
                    return channel.getInvertedErr();
                }

                @Override
                public int waitFor() throws InterruptedException {
                    return channel.waitFor(ClientChannel.CLOSED, 0);
                }

                @Override
                public int exitValue() {
                    return channel.getExitStatus();
                }

                @Override
                public void destroy() {
                    channel.close(true);
                }
            };
        }
View Full Code Here

    public void testCommandDeadlock() throws Exception {
        SshClient client = SshClient.setUpDefaultClient();
        client.start();
        ClientSession session = client.connect("localhost", port).await().getSession();
        session.authPassword("smx", "smx").await().isSuccess();
        ChannelExec channel = session.createExecChannel("test");
        channel.setOut(new NoCloseOutputStream(System.out));
        channel.setErr(new NoCloseOutputStream(System.err));
        channel.open().await();
        Thread.sleep(100);
        try {
            for (int i = 0; i < 100; i++) {
                channel.getInvertedIn().write("a".getBytes());
                channel.getInvertedIn().flush();
            }
        } catch (SshException e) {
            // That's ok, the channel is being closed by the other side
        }
        assertEquals(ChannelExec.CLOSED, channel.waitFor(ChannelExec.CLOSED, 0) & ChannelExec.CLOSED);
        session.close(false).await();
        client.stop();
    }
View Full Code Here

        registerChannel(channel);
        return channel;
    }

    public ChannelExec createExecChannel(String command) throws Exception {
        ChannelExec channel = new ChannelExec(command);
        registerChannel(channel);
        return channel;
    }
View Full Code Here

        client.stop();
        sshd.stop();
    }

    private void execute(ClientSession session, String command) throws Exception {
        ChannelExec channel = session.createExecChannel(command);
        channel.setOut(System.out);
        channel.setErr(System.err);
        channel.open().verify();
        channel.waitFor(ClientChannel.CLOSED, 0);
        if (channel.getExitStatus() != null) {
            int s = channel.getExitStatus();
            if (s != 0) {
                throw new Exception("Command failed with status " + s);
            }
        }
    }
View Full Code Here

        getConnectionService().registerChannel(channel);
        return channel;
    }

    public ChannelExec createExecChannel(String command) throws IOException {
        ChannelExec channel = new ChannelExec(command);
        getConnectionService().registerChannel(channel);
        return channel;
    }
View Full Code Here

    public void testCommandDeadlock() throws Exception {
        SshClient client = SshClient.setUpDefaultClient();
        client.start();
        ClientSession session = client.connect("localhost", port).await().getSession();
        session.authPassword("smx", "smx").await().isSuccess();
        ChannelExec channel = session.createExecChannel("test");
        channel.setOut(new NoCloseOutputStream(System.out));
        channel.setErr(new NoCloseOutputStream(System.err));
        channel.open().await();
        Thread.sleep(100);
        try {
            for (int i = 0; i < 100; i++) {
                channel.getInvertedIn().write("a".getBytes());
                channel.getInvertedIn().flush();
            }
        } catch (SshException e) {
            // That's ok, the channel is being closed by the other side
        }
        assertEquals(ChannelExec.CLOSED, channel.waitFor(ChannelExec.CLOSED, 0) & ChannelExec.CLOSED);
        session.close(false).await();
        client.stop();
    }
View Full Code Here

            if (!target.isDirectory()) {
                throw new SshException("Target directory " + target.toString() + " is not a directory");
            }
        }

        ChannelExec channel = clientSession.createExecChannel(sb.toString());
        try {
            channel.open().await();
        } catch (InterruptedException e) {
            throw (IOException) new InterruptedIOException().initCause(e);
        }

        ScpHelper helper = new ScpHelper(channel.getInvertedOut(), channel.getInvertedIn(), fs);

        helper.receive(target,
                       options.contains(Option.Recursive),
                       options.contains(Option.TargetIsDirectory),
                       options.contains(Option.PreserveAttributes));

        channel.close(false);
    }
View Full Code Here

        }
        sb.append(" -t");
        sb.append(" --");
        sb.append(" ");
        sb.append(remote);
        ChannelExec channel = clientSession.createExecChannel(sb.toString());
        try {
            channel.open().await();
        } catch (InterruptedException e) {
            throw (IOException) new InterruptedIOException().initCause(e);
        }

        FileSystemFactory factory = clientSession.getFactoryManager().getFileSystemFactory();
        FileSystemView fs = factory.createFileSystemView(clientSession);
        ScpHelper helper = new ScpHelper(channel.getInvertedOut(), channel.getInvertedIn(), fs);

        helper.send(Arrays.asList(local),
                    options.contains(Option.Recursive),
                    options.contains(Option.PreserveAttributes));

        channel.close(false);
    }
View Full Code Here

TOP

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

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.