public class Ssh2Session extends Ssh2Channel implements SshSession
SESSION_CHANNEL
CHANNEL_CLOSED, CHANNEL_OPEN, CHANNEL_UNINITIALIZED, channelid, manager, ms, state
EXITCODE_NOT_RECEIVED
Constructor and Description |
---|
Ssh2Session(int windowsize,
int packetsize,
Ssh2Client client)
Construct a session channel.
|
Modifier and Type | Method and Description |
---|---|
void |
changeTerminalDimensions(int cols,
int rows,
int width,
int height)
Change the dimensions of the terminal window.
|
protected void |
channelRequest(String requesttype,
boolean wantreply,
byte[] requestdata)
This overidden method handles the "exit-status", "exit-signal" and
"xon-xoff" channel requests.
|
protected void |
checkCloseStatus(boolean remoteClosed) |
boolean |
executeCommand(String cmd)
Execute a command.
|
boolean |
executeCommand(String cmd,
String charset)
Execute a command.
|
int |
exitCode()
Return the exit code of the process once complete.
|
SshClient |
getClient()
The SshClient that this channel belongs to
|
String |
getExitSignalInfo()
Get the exit signal information, may be an empty string.
|
InputStream |
getStderrInputStream()
Get an InputStream to read the process stderr.
|
String |
getTerm()
Returns the term type of any pseudo terminal successfully attached to session.
|
boolean |
hasExitSignal()
Determine whether the remote process was signalled.
|
boolean |
isFlowControlEnabled()
On many systems it is possible to determine whether a pseudo-terminal is
using control-S/ control-Q flow control.
|
protected void |
processExtendedData(int typecode,
int length,
SshChannelMessage msg)
Called when extended data arrives.
|
boolean |
requestPseudoTerminal(String term,
int cols,
int rows,
int width,
int height)
The remote process may require a pseudo terminal.
|
boolean |
requestPseudoTerminal(String term,
int cols,
int rows,
int width,
int height,
byte[] modes)
The remote process may require a pseudo terminal.
|
boolean |
requestPseudoTerminal(String term,
int cols,
int rows,
int width,
int height,
PseudoTerminalModes terminalModes)
The remote process may require a pseudo terminal.
|
boolean |
setEnvironmentVariable(String name,
String value)
The SSH2 session supports the setting of environments variables however
in our experience no server to date allows unconditional setting of
variables.
|
void |
signal(String signal)
Send a signal to the remote process.
|
boolean |
startShell()
Start the users default shell.
|
boolean |
startSubsystem(String subsystem)
SSH2 supports special subsystems that are identified by a name rather
than a command string, an example of an SSH2 subsystem is SFTP.
|
addChannelEventListener, channelEOF, close, create, createExtendedDataStream, equals, free, getConnection, getInputStream, getMaximumLocalPacketLength, getMaximumLocalWindowSize, getMaximumRemotePacketLength, getMaximumRemoteWindowSize, getMessageStore, getName, getOutputStream, getRemoteWindow, getStickyMessageIds, idle, isSendKeepAliveOnIdle, open, open, processChannelMessage, processStandardData, removeChannelEventListener, sendRequest, sendRequest, setAutoConsumeInput, setSendKeepAliveOnIdle
getChannelId, getMessageRouter, init, isClosed, waitForOpen
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, getInputStream, getOutputStream, isClosed
addChannelEventListener, getChannelId, getMaximumLocalPacketLength, getMaximumLocalWindowSize, getMaximumRemotePacketLength, getMaximumRemoteWindowSize, getMessageRouter, getRemoteWindow, removeChannelEventListener, setAutoConsumeInput, waitForOpen
public Ssh2Session(int windowsize, int packetsize, Ssh2Client client)
windowsize
- the initial/maximum window space availablepacketsize
- the maximum packet sizepublic SshClient getClient()
SshChannel
getClient
in interface SshChannel
getClient
in interface SshSession
getClient
in class Ssh2Channel
public String getTerm()
SshSession
getTerm
in interface SshSession
protected void processExtendedData(int typecode, int length, SshChannelMessage msg) throws SshException
Ssh2Channel
com.maverick.ssh.ChannelEventListener#extendedDataReceived(com.maverick.ssh.Channel, byte[], int, int, int)
event so to maintain code compatibility always call the super
method in any overidden method.processExtendedData
in class Ssh2Channel
typecode
- the type of extended dataSshException
public InputStream getStderrInputStream()
SshSession
getStderrInputStream
in interface SshSession
public boolean requestPseudoTerminal(String term, int cols, int rows, int width, int height) throws SshException
SshSession
requestPseudoTerminal
in interface SshSession
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)true
if the pty was allocated, otherwise false
SshException
public boolean requestPseudoTerminal(String term, int cols, int rows, int width, int height, PseudoTerminalModes terminalModes) throws SshException
SshSession
requestPseudoTerminal
in interface SshSession
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)terminalModes
- the known terminal modestrue
if the pty was allocated, otherwise false
SshException
public boolean requestPseudoTerminal(String term, int cols, int rows, int width, int height, byte[] modes) throws SshException
SshSession
requestPseudoTerminal
in interface SshSession
term
- the terminal type e.g "vt100"cols
- the number of columnsrows
- the number of rowswidth
- the width of the terminal (informational only, can be zero)height
- the height of the terminal (informational only, can be zero)modes
- an array of encoded terminal modes as described in the
SSH protocol specifications.true
if the pty was allocated, otherwise false
SshException
public boolean startShell() throws SshException
SshSession
startShell
in interface SshSession
true
if the shell was started, otherwise
false
SshException
public boolean executeCommand(String cmd) throws SshException
SshSession
executeCommand
in interface SshSession
true
if the command was accepted, otherwise
false
. This may not return false if the
command is incorrect, it should only be used as an
indication that the command was accepted and that the
server will attempt to execute it.SshException
public boolean executeCommand(String cmd, String charset) throws SshException
SshSession
executeCommand
in interface SshSession
true
if the command was accepted, otherwise
false
. This may not return false if the
command is incorrect, it should only be used as an
indication that the command was accepted and that the
server will attempt to execute it.SshException
public boolean startSubsystem(String subsystem) throws SshException
subsystem
- the name of the subsystem, for example "sftp"true
if the subsystem was started, otherwise
false
SshException
public boolean setEnvironmentVariable(String name, String value) throws SshException
SshException
public void changeTerminalDimensions(int cols, int rows, int width, int height) throws SshException
SshSession
changeTerminalDimensions
in interface SshSession
SshException
public boolean isFlowControlEnabled()
true
the
client is allowed to do flow control using control-S and control-Qpublic void signal(String signal) throws SshException
ABRT ALRM FPE HUP ILL INT KILL PIPE QUIT SEGV TERM USR1 USR2
signal
- IOException
SshException
protected void channelRequest(String requesttype, boolean wantreply, byte[] requestdata) throws SshException
channelRequest
in class Ssh2Channel
requesttype
- the name of the requestwantreply
- specifies whether the remote side requires a success/failure
messagerequestdata
- the request dataSshException
public int exitCode()
SshSession
exitCode
in interface SshSession
protected void checkCloseStatus(boolean remoteClosed)
checkCloseStatus
in class Ssh2Channel
public boolean hasExitSignal()
true
if a signal was received, otherwise
false
public String getExitSignalInfo()
Copyright © 2024. All rights reserved.