Package org.apache.sshd.client.channel
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.ChannelSession
org.apache.sshd.client.channel.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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.channel.AbstractChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState, AbstractChannel.PacketValidator
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T extends Object>
Nested classes/interfaces inherited from interface org.apache.sshd.common.channel.StreamingChannel
StreamingChannel.Streaming
-
Field Summary
Fields inherited from class org.apache.sshd.client.channel.ChannelSession
pumper, pumperService
Fields inherited from class org.apache.sshd.client.channel.AbstractClientChannel
asyncErr, asyncIn, asyncOut, err, exitSignalHolder, exitStatusHolder, in, invertedErr, invertedIn, invertedOut, opened, openFailureLang, openFailureMsg, openFailureReason, openFuture, out, redirectErrorStream, streaming
Fields inherited from class org.apache.sshd.common.channel.AbstractChannel
channelListenerProxy, channelListeners, closeSignaled, DEFAULT_PACKET_VALIDATOR, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaled
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
Fields inherited from interface org.apache.sshd.common.channel.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
Fields 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
ConstructorDescriptionPtyCapableChannelSession
(boolean usePty, PtyChannelConfigurationHolder configHolder, Map<String, ?> env) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
int
int
int
int
boolean
boolean
isUsePty()
protected String
resolvePtyType
(PtyChannelConfigurationHolder configHolder) void
sendWindowChange
(int columns, int lines) void
sendWindowChange
(int columns, int lines, int height, int width) void
setAgentForwarding
(boolean agentForwarding) void
setPtyColumns
(int ptyColumns) void
setPtyHeight
(int ptyHeight) void
setPtyLines
(int ptyLines) void
setPtyModes
(Map<PtyMode, Integer> ptyModes) void
setPtyType
(String ptyType) void
setPtyWidth
(int ptyWidth) void
void
setUsePty
(boolean usePty) Methods inherited from class org.apache.sshd.client.channel.ChannelSession
closeImmediately0, doOpen, getInnerCloseable, handleInternalRequest, handleXonXoff, pumpInputStream, securedRead, sendEnvVariables, setEnv
Methods inherited from class org.apache.sshd.client.channel.AbstractClientChannel
addChannelSignalRequestHandlers, doWriteData, doWriteExtendedData, getAsyncErr, getAsyncIn, getAsyncOut, getChannelState, getChannelType, getErr, getExitSignal, getExitStatus, getIn, getInvertedErr, getInvertedIn, getInvertedOut, getOut, getStreaming, handleOpenFailure, handleOpenSuccess, handleWindowAdjust, isRedirectErrorStream, mayWrite, open, open, setErr, setIn, setOut, setRedirectErrorStream, setStreaming, updateCurrentChannelState, waitFor
Methods inherited from class org.apache.sshd.common.channel.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, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamWriterResolver, sendEof, sendResponse, sendWindowAdjust, setAttribute, setChannelStreamWriterResolver, setPacketValidator, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacket
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
Methods 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, warn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCount
Methods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
Methods inherited from interface org.apache.sshd.common.channel.Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacket
Methods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelId
Methods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListener
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
Methods inherited from interface org.apache.sshd.client.channel.ClientChannel
getClientSession, waitFor
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSession, getSessionContext
-
Constructor Details
-
PtyCapableChannelSession
public PtyCapableChannelSession(boolean usePty, PtyChannelConfigurationHolder configHolder, Map<String, ?> env)
-
-
Method Details
-
resolvePtyType
-
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:
getPtyType
in interfacePtyChannelConfigurationHolder
-
setPtyType
- Specified by:
setPtyType
in interfacePtyChannelConfigurationMutator
-
getPtyColumns
public int getPtyColumns()- Specified by:
getPtyColumns
in interfacePtyChannelConfigurationHolder
-
setPtyColumns
public void setPtyColumns(int ptyColumns) - Specified by:
setPtyColumns
in interfacePtyChannelConfigurationMutator
-
getPtyLines
public int getPtyLines()- Specified by:
getPtyLines
in interfacePtyChannelConfigurationHolder
-
setPtyLines
public void setPtyLines(int ptyLines) - Specified by:
setPtyLines
in interfacePtyChannelConfigurationMutator
-
getPtyWidth
public int getPtyWidth()- Specified by:
getPtyWidth
in interfacePtyChannelConfigurationHolder
-
setPtyWidth
public void setPtyWidth(int ptyWidth) - Specified by:
setPtyWidth
in interfacePtyChannelConfigurationMutator
-
getPtyHeight
public int getPtyHeight()- Specified by:
getPtyHeight
in interfacePtyChannelConfigurationHolder
-
setPtyHeight
public void setPtyHeight(int ptyHeight) - Specified by:
setPtyHeight
in interfacePtyChannelConfigurationMutator
-
getPtyModes
- Specified by:
getPtyModes
in interfacePtyChannelConfigurationHolder
-
setPtyModes
- Specified by:
setPtyModes
in interfacePtyChannelConfigurationMutator
-
sendWindowChange
- Throws:
IOException
-
sendWindowChange
- Throws:
IOException
-
doOpenPty
- Throws:
IOException
-