Class PtyCapableChannelSession

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientChannel, ClientSessionHolder, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, Channel, ChannelIdentifier, ChannelListenerManager, org.apache.sshd.common.channel.PtyChannelConfigurationHolder, org.apache.sshd.common.channel.PtyChannelConfigurationMutator, StreamingChannel, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.session.SessionContextHolder, SessionHolder<Session>, org.apache.sshd.common.util.threads.ExecutorServiceCarrier
Direct Known Subclasses:
ChannelExec, ChannelShell

public class PtyCapableChannelSession extends ChannelSession implements org.apache.sshd.common.channel.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
  • Constructor Details

    • PtyCapableChannelSession

      public PtyCapableChannelSession(boolean usePty, org.apache.sshd.common.channel.PtyChannelConfigurationHolder configHolder, Map<String,?> env)
  • Method Details

    • resolvePtyType

      protected String resolvePtyType(org.apache.sshd.common.channel.PtyChannelConfigurationHolder configHolder)
    • setupSensibleDefaultPty

      public void setupSensibleDefaultPty()
    • isAgentForwarding

      public boolean isAgentForwarding()
    • setAgentForwarding

      public void setAgentForwarding(boolean agentForwarding)
    • isUsePty

      public boolean isUsePty()
    • setUsePty

      public void setUsePty(boolean usePty)
    • getPtyType

      public String getPtyType()
      Specified by:
      getPtyType in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyType

      public void setPtyType(String ptyType)
      Specified by:
      setPtyType in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • getPtyColumns

      public int getPtyColumns()
      Specified by:
      getPtyColumns in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyColumns

      public void setPtyColumns(int ptyColumns)
      Specified by:
      setPtyColumns in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • getPtyLines

      public int getPtyLines()
      Specified by:
      getPtyLines in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyLines

      public void setPtyLines(int ptyLines)
      Specified by:
      setPtyLines in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • getPtyWidth

      public int getPtyWidth()
      Specified by:
      getPtyWidth in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyWidth

      public void setPtyWidth(int ptyWidth)
      Specified by:
      setPtyWidth in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • getPtyHeight

      public int getPtyHeight()
      Specified by:
      getPtyHeight in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyHeight

      public void setPtyHeight(int ptyHeight)
      Specified by:
      setPtyHeight in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • getPtyModes

      public Map<org.apache.sshd.common.channel.PtyMode, Integer> getPtyModes()
      Specified by:
      getPtyModes in interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
    • setPtyModes

      public void setPtyModes(Map<org.apache.sshd.common.channel.PtyMode, Integer> ptyModes)
      Specified by:
      setPtyModes in interface org.apache.sshd.common.channel.PtyChannelConfigurationMutator
    • sendWindowChange

      public void sendWindowChange(int columns, int lines) throws IOException
      Throws:
      IOException
    • sendWindowChange

      public void sendWindowChange(int columns, int lines, int height, int width) throws IOException
      Throws:
      IOException
    • doOpenPty

      protected void doOpenPty() throws IOException
      Throws:
      IOException