Class PtyCapableChannelSession

All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientChannel, ClientSessionHolder, AttributeRepository, AttributeStore, Channel, ChannelIdentifier, ChannelListenerManager, PtyChannelConfigurationHolder, PtyChannelConfigurationMutator, StreamingChannel, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, Closeable, PropertyResolver, SessionContextHolder, SessionHolder<Session>, ExecutorServiceCarrier
Direct Known Subclasses:
ChannelExec, ChannelShell

public class PtyCapableChannelSession extends ChannelSession implements PtyChannelConfigurationMutator

Serves as the base channel session for executing remote commands - including a full shell. Note: all the configuration changes via the various setXXX methods must be made before the channel is actually open. If they are invoked afterwards then they have no effect (silently ignored).

A typical code snippet would be:

 
 try (client = SshClient.setUpDefaultClient()) {
      client.start();

      try (ClientSession s = client.connect(getCurrentTestName(), "localhost", port).verify(CONNECT_TIMEOUT).getSession()) {
          s.addPasswordIdentity(getCurrentTestName());
          s.auth().verify(AUTH_TIMEOUT);

          try (ChannelExec shell = s.createExecChannel("my super duper command")) {
              shell.setEnv("var1", "val1");
              shell.setEnv("var2", "val2");
              ...etc...

              shell.setPtyType(...);
              shell.setPtyLines(...);
              ...etc...

              shell.open().verify(OPEN_TIMEOUT);
              shell.waitFor(ClientChannel.CLOSED, TimeUnit.SECONDS.toMillis(17L));    // can use zero for infinite wait

              Integer status = shell.getExitStatus();
              if (status.intValue() != 0) {
                  ...error...
              }
          }
      } finally {
          client.stop();
      }
 }
 
 
Author:
Apache MINA SSHD Project