Package org.apache.sshd.client.channel

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


  public ChannelSession openSession(String command) throws SshException {
    try {
      boolean useAgentForwarding = sshContext.isAgentForwarding();

      ChannelSession clientChannel = BugFixChannelExec.createExecChannel(sshClientSession, command,
          useAgentForwarding);
      return clientChannel;
    } catch (Exception e) {
      ExceptionUtils.handleInterrupted(e);
      throw new SshException("Error creating channel", e);
View Full Code Here


    }
  }

  int sshExecute(String command, final OutputStream stdout, final OutputStream stderr, ProcessStartListener listener,
      TimeSpan timeout) throws SshException, IOException, InterruptedException {
    ChannelSession sshChannel = null;
    try {
      sshChannel = ensureConnected().openSession(command);

      sshChannel.setIn(new ByteArrayInputStream(new byte[0]));
      sshChannel.setOut(stdout);
      sshChannel.setErr(stderr);
      try {
        sshChannel.open().await(DEFAULT_SSH_CONNECT_TIMEOUT.getTotalMilliseconds());
      } catch (Exception e) {
        ExceptionUtils.handleInterrupted(e);
        throw new SshException("Ssh error opening channel", e);
      }

      if (listener != null) {
        throw new UnsupportedOperationException();
        // listener.startedProcess(sshChannel.getStdin());
      }

      if (timeout == null) {
        timeout = TimeSpan.ZERO;
      }

      // Wait for everything to finish
      int flags = sshChannel.waitFor(ClientChannel.EOF | ClientChannel.CLOSED, timeout.getTotalMilliseconds());
      if ((flags & ClientChannel.TIMEOUT) != 0) {
        closeAndRemoveFromPool();
        throw new SshException("Timeout while waiting for SSH task to complete.  Timeout was " + timeout);
      }

      flags = sshChannel.waitFor(ClientChannel.EXIT_STATUS, 30000);
      if ((flags & ClientChannel.TIMEOUT) != 0) {
        closeAndRemoveFromPool();
        throw new SshException("Timeout while waiting for exit code.  Timeout was " + timeout);
      }

      Integer exitCode = getExitStatus(sshChannel);

      if (exitCode == null) {
        closeAndRemoveFromPool();
        throw new SshException("No exit code returned");
      }

      return exitCode;
    } finally {
      if (sshChannel != null) {
        sshChannel.close(false);
      }
    }
  }
View Full Code Here

TOP

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

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.