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.GracefulState
AbstractCloseable.State
ClientChannel.ClientChannelEvent, ClientChannel.Streaming
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COLUMNS_COUNT |
static int |
DEFAULT_HEIGHT |
static Map<PtyMode,Integer> |
DEFAULT_PTY_MODES |
static int |
DEFAULT_ROWS_COUNT |
static int |
DEFAULT_WIDTH |
asyncErr, asyncIn, asyncOut, err, exitSignalHolder, exitStatusHolder, in, invertedErr, invertedIn, invertedOut, opened, openFailureLang, openFailureMsg, openFailureReason, openFuture, out, streaming, type
channelListenerProxy, channelListeners, eof, executor, gracefulFuture, gracefulState, handlers, localWindow, remoteWindow, RESPONSE_BUFFER_GROWTH_FACTOR, service, shutdownExecutor
closeFuture, lock, state
log
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
Constructor and Description |
---|
PtyCapableChannelSession(boolean usePty) |
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() |
void |
sendWindowChange(int columns,
int lines) |
void |
sendWindowChange(int columns,
int lines,
int height,
int width) |
void |
setAgentForwarding(boolean agentForwarding) |
void |
setEnv(String key,
String value) |
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) |
doCloseImmediately, doOpen, handleInternalRequest, handleXonXoff, pumpInputStream, securedRead
addChannelSignalRequestHandlers, doWriteData, doWriteExtendedData, getAsyncErr, getAsyncIn, getAsyncOut, getErr, getExitSignal, getExitStatus, getIn, getInnerCloseable, getInvertedErr, getInvertedIn, getInvertedOut, getOut, getStreaming, handleOpenFailure, handleOpenSuccess, handleWindowAdjust, open, open, setErr, setIn, setOut, setStreaming, waitFor
addChannelListener, addPendingRequest, addRequestHandler, configureWindow, getChannelListenerProxy, getExecutorService, getId, getLocalWindow, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getSession, handleChannelRequest, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, handleUnknownChannelRequest, init, isEofSignalled, isShutdownOnExit, notifyStateChanged, preClose, removeChannelListener, removePendingRequest, sendEof, sendResponse, sendWindowAdjust, setEofSignalled, setExecutorService, setRecipient, setShutdownOnExit, toString, writePacket
doCloseGracefully
builder, close, isClosed, isClosing
close, isOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close
getId, getLocalWindow, getRecipient, getRemoteWindow, getSession, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, handleSuccess, init
addChannelListener, getChannelListenerProxy, removeChannelListener
getParentPropertyResolver, getProperties
public 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 void setupSensibleDefaultPty()
public boolean isAgentForwarding()
public void setAgentForwarding(boolean agentForwarding)
public boolean isUsePty()
public void setUsePty(boolean usePty)
public String getPtyType()
public void setPtyType(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 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–2016 The Apache Software Foundation. All rights reserved.