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
org.apache.sshd.common.util.closeable.AbstractInnerCloseable
org.apache.sshd.common.channel.AbstractChannel
org.apache.sshd.client.channel.AbstractClientChannel
org.apache.sshd.client.channel.AsyncCapableClientChannel
org.apache.sshd.client.channel.ChannelSession
org.apache.sshd.client.channel.PtyCapableChannelSession
- 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
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState, AbstractChannel.PacketValidatorNested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
org.apache.sshd.common.AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface StreamingChannel
StreamingChannel.Streaming -
Field Summary
Fields inherited from class ChannelSession
pumper, pumperServiceFields inherited from class AsyncCapableClientChannel
withErrorStreamFields inherited from class AbstractClientChannel
asyncErr, asyncIn, asyncOut, err, exitSignalHolder, exitStatusHolder, in, invertedErr, invertedIn, invertedOut, opened, openFailureLang, openFailureMsg, openFailureReason, openFuture, out, redirectErrorStream, streamingFields inherited from class AbstractChannel
channelListenerProxy, channelListeners, closeSignaled, DEFAULT_PACKET_VALIDATOR, eofReceived, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaledFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMFields inherited from interface ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTYFields inherited from interface org.apache.sshd.common.channel.PtyChannelConfigurationHolder
DEFAULT_COLUMNS_COUNT, DEFAULT_HEIGHT, DEFAULT_PTY_MODES, DEFAULT_ROWS_COUNT, DEFAULT_WIDTH, DUMMY_PTY_TYPE, WINDOWS_PTY_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionPtyCapableChannelSession(boolean usePty, org.apache.sshd.common.channel.PtyChannelConfigurationHolder configHolder, Map<String, ?> env) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidintintintintbooleanbooleanisUsePty()protected StringresolvePtyType(org.apache.sshd.common.channel.PtyChannelConfigurationHolder configHolder) voidsendWindowChange(int columns, int lines) voidsendWindowChange(int columns, int lines, int height, int width) voidsetAgentForwarding(boolean agentForwarding) voidsetPtyColumns(int ptyColumns) voidsetPtyHeight(int ptyHeight) voidsetPtyLines(int ptyLines) voidsetPtyModes(Map<org.apache.sshd.common.channel.PtyMode, Integer> ptyModes) voidsetPtyType(String ptyType) voidsetPtyWidth(int ptyWidth) voidvoidsetUsePty(boolean usePty) Methods inherited from class ChannelSession
handleInternalRequest, handleXonXoff, sendEnvVariables, setEnvMethods inherited from class AsyncCapableClientChannel
closeImmediately0, doOpen, doWriteExtendedData, getAsyncErr, getErr, getInnerCloseable, getInvertedErr, pumpInputStream, securedRead, setErrMethods inherited from class AbstractClientChannel
addChannelSignalRequestHandlers, doWriteData, getAsyncIn, getAsyncOut, getChannelState, getChannelType, getExitSignal, getExitStatus, getIn, getInvertedIn, getInvertedOut, getOut, getStreaming, handleOpenFailure, handleOpenSuccess, handleWindowAdjust, isRedirectErrorStream, mayWrite, open, open, setIn, setOut, setRedirectErrorStream, setStreaming, updateCurrentChannelState, waitForMethods inherited from class AbstractChannel
addChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelId, getChannelListenerProxy, getChannelStreamWriterResolver, getExecutorService, getLocalWindow, getPacketValidator, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getRequestHandlers, getSession, handleChannelRegistrationResult, handleChannelRequest, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, handleUnknownChannelRequest, init, invokeChannelSignaller, isEofSent, isEofSignalled, isInitialized, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamWriterResolver, sendEof, sendResponse, sendWindowAdjust, setAttribute, setChannelStreamWriterResolver, setPacketValidator, setRecipient, signalChannelClosed, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacketMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacketMethods inherited from interface ChannelIdentifier
getChannelIdMethods inherited from interface ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface ClientChannel
getClientSession, waitForMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface SessionHolder
getSession, getSessionContext
-
Constructor Details
-
PtyCapableChannelSession
-
-
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
- Specified by:
getPtyTypein interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationHolder
-
setPtyType
- Specified by:
setPtyTypein interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationMutator
-
getPtyColumns
public int getPtyColumns()- Specified by:
getPtyColumnsin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationHolder
-
setPtyColumns
public void setPtyColumns(int ptyColumns) - Specified by:
setPtyColumnsin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationMutator
-
getPtyLines
public int getPtyLines()- Specified by:
getPtyLinesin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationHolder
-
setPtyLines
public void setPtyLines(int ptyLines) - Specified by:
setPtyLinesin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationMutator
-
getPtyWidth
public int getPtyWidth()- Specified by:
getPtyWidthin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationHolder
-
setPtyWidth
public void setPtyWidth(int ptyWidth) - Specified by:
setPtyWidthin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationMutator
-
getPtyHeight
public int getPtyHeight()- Specified by:
getPtyHeightin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationHolder
-
setPtyHeight
public void setPtyHeight(int ptyHeight) - Specified by:
setPtyHeightin interfaceorg.apache.sshd.common.channel.PtyChannelConfigurationMutator
-
getPtyModes
-
setPtyModes
-
sendWindowChange
- Throws:
IOException
-
sendWindowChange
- Throws:
IOException
-
doOpenPty
- Throws:
IOException
-