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();
}
}
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState
AbstractCloseable.State
AttributeRepository.AttributeKey<T>
StreamingChannel.Streaming
pumper, pumperService
asyncErr, asyncIn, asyncOut, err, exitSignalHolder, exitStatusHolder, in, invertedErr, invertedIn, invertedOut, opened, openFailureLang, openFailureMsg, openFailureReason, openFuture, out, redirectErrorStream, streaming
channelListenerProxy, channelListeners, closeSignaled, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaled
closeFuture, futureLock, state
log
DEFAULT_COLUMNS_COUNT, DEFAULT_HEIGHT, DEFAULT_PTY_MODES, DEFAULT_ROWS_COUNT, DEFAULT_WIDTH, DUMMY_PTY_TYPE, WINDOWS_PTY_TYPE
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
EMPTY
NONE
Constructor and Description |
---|
PtyCapableChannelSession(boolean usePty,
PtyChannelConfigurationHolder configHolder,
Map<String,?> env) |
Modifier and Type | Method and Description |
---|---|
protected void |
doOpenPty() |
int |
getPtyColumns() |
int |
getPtyHeight() |
int |
getPtyLines() |
Map<PtyMode,Integer> |
getPtyModes() |
String |
getPtyType() |
int |
getPtyWidth() |
boolean |
isAgentForwarding() |
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 |
setupSensibleDefaultPty() |
void |
setUsePty(boolean usePty) |
closeImmediately0, doOpen, getInnerCloseable, handleInternalRequest, handleXonXoff, pumpInputStream, securedRead, sendEnvVariables, setEnv
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
addChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelId, getChannelListenerProxy, getChannelStreamWriterResolver, getExecutorService, getLocalWindow, 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, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacket
doCloseGracefully, doCloseImmediately
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
copyConfiguration, setupSensitiveDefaultPtyConfiguration
getClientSession, validateCommandExitStatusCode, waitFor
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, resolveAttribute, writePacket
getSession, getSessionContext
getChannelId
addChannelListener, getChannelListenerProxy, removeChannelListener
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty, isEmpty
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
attributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePair
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
public PtyCapableChannelSession(boolean usePty, PtyChannelConfigurationHolder configHolder, Map<String,?> env)
protected String resolvePtyType(PtyChannelConfigurationHolder configHolder)
public void setupSensibleDefaultPty()
public boolean isAgentForwarding()
public void setAgentForwarding(boolean agentForwarding)
public boolean isUsePty()
public void setUsePty(boolean usePty)
public String getPtyType()
getPtyType
in interface PtyChannelConfigurationHolder
public void setPtyType(String ptyType)
setPtyType
in interface PtyChannelConfigurationMutator
public int getPtyColumns()
getPtyColumns
in interface PtyChannelConfigurationHolder
public void setPtyColumns(int ptyColumns)
setPtyColumns
in interface PtyChannelConfigurationMutator
public int getPtyLines()
getPtyLines
in interface PtyChannelConfigurationHolder
public void setPtyLines(int ptyLines)
setPtyLines
in interface PtyChannelConfigurationMutator
public int getPtyWidth()
getPtyWidth
in interface PtyChannelConfigurationHolder
public void setPtyWidth(int ptyWidth)
setPtyWidth
in interface PtyChannelConfigurationMutator
public int getPtyHeight()
getPtyHeight
in interface PtyChannelConfigurationHolder
public void setPtyHeight(int ptyHeight)
setPtyHeight
in interface PtyChannelConfigurationMutator
public Map<PtyMode,Integer> getPtyModes()
getPtyModes
in interface PtyChannelConfigurationHolder
public void setPtyModes(Map<PtyMode,Integer> ptyModes)
setPtyModes
in interface PtyChannelConfigurationMutator
public void sendWindowChange(int columns, int lines) throws IOException
IOException
public void sendWindowChange(int columns, int lines, int height, int width) throws IOException
IOException
protected void doOpenPty() throws IOException
IOException
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.