public class PtyCapableChannelSession extends ChannelSession
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(7L, TimeUnit.SECONDS).getSession()) {
s.addPasswordIdentity(getCurrentTestName());
s.auth().verify(5L, TimeUnit.SECONDS);
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(5L, TimeUnit.SECONDS);
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.GracefulStateAbstractCloseable.StateClientChannel.StreamingAttributeRepository.AttributeKey<T>| Modifier and Type | Field and Description |
|---|---|
private boolean |
agentForwarding |
static int |
DEFAULT_COLUMNS_COUNT |
static int |
DEFAULT_HEIGHT |
static java.util.Map<PtyMode,java.lang.Integer> |
DEFAULT_PTY_MODES |
static int |
DEFAULT_ROWS_COUNT |
static int |
DEFAULT_WIDTH |
private java.util.Map<java.lang.String,java.lang.String> |
env |
private int |
ptyColumns |
private int |
ptyHeight |
private int |
ptyLines |
private java.util.Map<PtyMode,java.lang.Integer> |
ptyModes |
private java.lang.String |
ptyType |
private int |
ptyWidth |
private boolean |
usePty |
asyncErr, asyncIn, asyncOut, err, exitSignalHolder, exitStatusHolder, in, invertedErr, invertedIn, invertedOut, opened, openFailureLang, openFailureMsg, openFailureReason, openFuture, out, streamingchannelListenerProxy, channelListeners, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, servicecloseFuture, lock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMEMPTYNONECLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT| Constructor and Description |
|---|
PtyCapableChannelSession(boolean usePty) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doOpenPty() |
int |
getPtyColumns() |
int |
getPtyHeight() |
int |
getPtyLines() |
java.util.Map<PtyMode,java.lang.Integer> |
getPtyModes() |
java.lang.String |
getPtyType() |
int |
getPtyWidth() |
boolean |
isAgentForwarding() |
boolean |
isUsePty() |
void |
sendWindowChange(int columns,
int lines) |
void |
sendWindowChange(int columns,
int lines,
int height,
int width) |
void |
setAgentForwarding(boolean agentForwarding) |
void |
setEnv(java.lang.String key,
java.lang.String value) |
void |
setPtyColumns(int ptyColumns) |
void |
setPtyHeight(int ptyHeight) |
void |
setPtyLines(int ptyLines) |
void |
setPtyModes(java.util.Map<PtyMode,java.lang.Integer> ptyModes) |
void |
setPtyType(java.lang.String ptyType) |
void |
setPtyWidth(int ptyWidth) |
void |
setupSensibleDefaultPty() |
void |
setUsePty(boolean usePty) |
closeImmediately0, doOpen, getInnerCloseable, handleInternalRequest, handleXonXoff, pumpInputStream, securedReadaddChannelSignalRequestHandlers, doWriteData, doWriteExtendedData, getAsyncErr, getAsyncIn, getAsyncOut, getChannelState, getChannelType, getClientSession, getErr, getExitSignal, getExitStatus, getIn, getInvertedErr, getInvertedIn, getInvertedOut, getOut, getStreaming, handleOpenFailure, handleOpenSuccess, handleWindowAdjust, open, open, setErr, setIn, setOut, setStreaming, updateCurrentChannelState, waitForaddChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelListenerProxy, getChannelStreamPacketWriterResolver, getExecutorService, getId, getLocalWindow, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getRequestHandlers, getSession, handleChannelRequest, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, handleUnknownChannelRequest, init, invokeChannelSignaller, isEofSent, isEofSignalled, isInitialized, notifyStateChanged, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamPacketWriterResolver, sendEof, sendResponse, sendWindowAdjust, setAttribute, setChannelStreamPacketWriterResolver, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacketdoCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, isClosed, isClosing, removeCloseFutureListenergetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitvalidateCommandExitStatusCodeaddRequestHandler, addRequestHandlers, getId, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, getSession, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, resolveAttributeaddChannelListener, getChannelListenerProxy, removeChannelListenergetBoolean, getBooleanProperty, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringPropertyclearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeattributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePairwritePacketgetChannelStreamPacketWriterResolver, resolveChannelStreamPacketWriter, resolveChannelStreamPacketWriterResolver, setChannelStreamPacketWriterResolveraddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerpublic static final int DEFAULT_COLUMNS_COUNT
public static final int DEFAULT_ROWS_COUNT
public static final int DEFAULT_WIDTH
public static final int DEFAULT_HEIGHT
public static final java.util.Map<PtyMode,java.lang.Integer> DEFAULT_PTY_MODES
private boolean agentForwarding
private boolean usePty
private java.lang.String ptyType
private int ptyColumns
private int ptyLines
private int ptyWidth
private int ptyHeight
private java.util.Map<PtyMode,java.lang.Integer> ptyModes
private final java.util.Map<java.lang.String,java.lang.String> env
public void setupSensibleDefaultPty()
public boolean isAgentForwarding()
public void setAgentForwarding(boolean agentForwarding)
public boolean isUsePty()
public void setUsePty(boolean usePty)
public java.lang.String getPtyType()
public void setPtyType(java.lang.String ptyType)
public int getPtyColumns()
public void setPtyColumns(int ptyColumns)
public int getPtyLines()
public void setPtyLines(int ptyLines)
public int getPtyWidth()
public void setPtyWidth(int ptyWidth)
public int getPtyHeight()
public void setPtyHeight(int ptyHeight)
public java.util.Map<PtyMode,java.lang.Integer> getPtyModes()
public void setPtyModes(java.util.Map<PtyMode,java.lang.Integer> ptyModes)
public void setEnv(java.lang.String key,
java.lang.String value)
public void sendWindowChange(int columns,
int lines)
throws java.io.IOException
java.io.IOExceptionpublic void sendWindowChange(int columns,
int lines,
int height,
int width)
throws java.io.IOException
java.io.IOExceptionprotected void doOpenPty()
throws java.io.IOException
java.io.IOException