com.maverick.ssh2
Class Ssh2Session

java.lang.Object
  extended bycom.maverick.ssh.message.SshAbstractChannel
      extended bycom.maverick.ssh2.Ssh2Channel
          extended bycom.maverick.ssh2.Ssh2Session
All Implemented Interfaces:
SshChannel, SshIO, SshSession

public class Ssh2Session
extends Ssh2Channel
implements SshSession

This class implements the SSH2 session channel, unlike SSH1 multiple sessions can be opened on the same SSH connection.

Author:
Lee David Painter

Field Summary
 
Fields inherited from class com.maverick.ssh2.Ssh2Channel
SESSION_CHANNEL
 
Fields inherited from class com.maverick.ssh.message.SshAbstractChannel
CHANNEL_CLOSED, CHANNEL_OPEN, CHANNEL_UNINITIALIZED, channelid, manager, ms, state
 
Fields inherited from interface com.maverick.ssh.SshSession
EXITCODE_NOT_RECEIVED
 
Constructor Summary
Ssh2Session(int windowsize, int packetsize, Ssh2Client client)
          Contruct a session channel.
 
Method Summary
 void changeTerminalDimensions(int cols, int rows, int width, int height)
          Change the dimensions of the terminal window.
protected  void channelRequest(java.lang.String requesttype, boolean wantreply, byte[] requestdata)
          This overidden method handles the "exit-status", "exit-signal" and "xon-xoff" channel requests.
 boolean executeCommand(java.lang.String cmd)
          Execute a command.
 boolean executeCommand(java.lang.String cmd, java.lang.String charset)
          Execute a command.
 int exitCode()
          Return the exit code of the process once complete.
 SshClient getClient()
          Get the client that created this session.
 java.lang.String getExitSignalInfo()
          Get the exit signal information, may be an empty string.
 java.io.InputStream getStderrInputStream()
          Get an InputStream to read the process stderr.
 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, byte[] buf, int offset, int len)
          Called when extended data arrives.
 boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height)
          The remote process may require a pseudo terminal.
 boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height, byte[] modes)
          The remote process may require a pseudo terminal.
 boolean requestPseudoTerminal(java.lang.String term, int cols, int rows, int width, int height, PseudoTerminalModes terminalModes)
          The remote process may require a pseudo terminal.
 boolean setEnvironmentVariable(java.lang.String name, java.lang.String value)
          The SSH2 session supports the setting of environments variables however in our experiance no server to date allows unconditional setting of variables.
 void signal(java.lang.String signal)
          Send a signal to the remote process.
 boolean startShell()
          Start the users default shell.
 boolean startSubsystem(java.lang.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.
 
Methods inherited from class com.maverick.ssh2.Ssh2Channel
addChannelEventListener, channelEOF, close, create, createExtendedDataStream, equals, getInputStream, getMessageStore, getName, getOutputStream, getStickyMessageIds, open, open, processChannelMessage, processStandardData, sendRequest, setAutoConsumeInput
 
Methods inherited from class com.maverick.ssh.message.SshAbstractChannel
getChannelId, init, isClosed
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.maverick.ssh.SshSession
close, getInputStream, getOutputStream, isClosed
 
Methods inherited from interface com.maverick.ssh.SshChannel
addChannelEventListener, getChannelId, setAutoConsumeInput
 

Constructor Detail

Ssh2Session

public Ssh2Session(int windowsize,
                   int packetsize,
                   Ssh2Client client)
Contruct a session channel.

Parameters:
windowsize - the initial/maximum window space available
packetsize - the maximum packet size
Method Detail

getClient

public SshClient getClient()
Description copied from interface: SshSession
Get the client that created this session.

Specified by:
getClient in interface SshSession
Returns:

processExtendedData

protected void processExtendedData(int typecode,
                                   byte[] buf,
                                   int offset,
                                   int len)
                            throws SshException
Description copied from class: Ssh2Channel
Called when extended data arrives. This method fires the 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.

Overrides:
processExtendedData in class Ssh2Channel
Parameters:
typecode - the type of extended data
buf - the data buffer
offset - the offset
len - the length
Throws:
SshException

getStderrInputStream

public java.io.InputStream getStderrInputStream()
Description copied from interface: SshSession
Get an InputStream to read the process stderr.

Specified by:
getStderrInputStream in interface SshSession
Returns:
the sessions stderr InputStream

requestPseudoTerminal

public boolean requestPseudoTerminal(java.lang.String term,
                                     int cols,
                                     int rows,
                                     int width,
                                     int height)
                              throws SshException
Description copied from interface: SshSession
The remote process may require a pseudo terminal. Call this method before executing a command or starting a shell.

Specified by:
requestPseudoTerminal in interface SshSession
Parameters:
term - the terminal type e.g "vt100"
cols - the number of columns
rows - the number of rows
width - the width of the terminal (informational only, can be zero)
height - the height of the terminal (informational only, can be zero)
Returns:
true if the pty was allocated, otherwise false
Throws:
SshException

requestPseudoTerminal

public boolean requestPseudoTerminal(java.lang.String term,
                                     int cols,
                                     int rows,
                                     int width,
                                     int height,
                                     PseudoTerminalModes terminalModes)
                              throws SshException
Description copied from interface: SshSession
The remote process may require a pseudo terminal. Call this method before executing a command or starting a shell.

Specified by:
requestPseudoTerminal in interface SshSession
Parameters:
term - the terminal type e.g "vt100"
cols - the number of columns
rows - the number of rows
width - 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 modes
Returns:
true if the pty was allocated, otherwise false
Throws:
SshException

requestPseudoTerminal

public boolean requestPseudoTerminal(java.lang.String term,
                                     int cols,
                                     int rows,
                                     int width,
                                     int height,
                                     byte[] modes)
                              throws SshException
Description copied from interface: SshSession
The remote process may require a pseudo terminal. Call this method before executing a command or starting a shell.

Specified by:
requestPseudoTerminal in interface SshSession
Parameters:
term - the terminal type e.g "vt100"
cols - the number of columns
rows - the number of rows
width - 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.
Returns:
true if the pty was allocated, otherwise false
Throws:
SshException

startShell

public boolean startShell()
                   throws SshException
Description copied from interface: SshSession
Start the users default shell.

Specified by:
startShell in interface SshSession
Returns:
true if the shell was started, otherwise false
Throws:
SshException

executeCommand

public boolean executeCommand(java.lang.String cmd)
                       throws SshException
Description copied from interface: SshSession
Execute a command.

Specified by:
executeCommand in interface SshSession
Parameters:
cmd -
Returns:
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.
Throws:
SshException

executeCommand

public boolean executeCommand(java.lang.String cmd,
                              java.lang.String charset)
                       throws SshException
Description copied from interface: SshSession
Execute a command.

Specified by:
executeCommand in interface SshSession
Parameters:
cmd -
Returns:
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.
Throws:
SshException

startSubsystem

public boolean startSubsystem(java.lang.String subsystem)
                       throws SshException
SSH2 supports special subsystems that are identified by a name rather than a command string, an example of an SSH2 subsystem is SFTP.

Parameters:
subsystem - the name of the subsystem, for example "sftp"
Returns:
true if the subsystem was started, otherwise false
Throws:
SshException

setEnvironmentVariable

public boolean setEnvironmentVariable(java.lang.String name,
                                      java.lang.String value)
                               throws SshException
The SSH2 session supports the setting of environments variables however in our experiance no server to date allows unconditional setting of variables. This method should be called before the command is started.

Throws:
SshException

changeTerminalDimensions

public void changeTerminalDimensions(int cols,
                                     int rows,
                                     int width,
                                     int height)
                              throws SshException
Description copied from interface: SshSession
Change the dimensions of the terminal window. This method should be called when the session is active and the user or application changes the size of the terminal window.

Specified by:
changeTerminalDimensions in interface SshSession
Parameters:
cols -
rows -
width -
height -
Throws:
SshException

isFlowControlEnabled

public boolean isFlowControlEnabled()
On many systems it is possible to determine whether a pseudo-terminal is using control-S/ control-Q flow control. When flow control is allowed it is often esirable to do the flow control at the client end to speed up responses to user requests. If this method returns true the client is allowed to do flow control using control-S and control-Q

Returns:

signal

public void signal(java.lang.String signal)
            throws SshException
Send a signal to the remote process. A signal can be delivered to the remote process using this method, some systems may not implement signals. The signal name should be one of the following values:
 ABRT
 ALRM
 FPE
 HUP
 ILL
 INT
 KILL
 PIPE
 QUIT
 SEGV
 TERM
 USR1
 USR2
 

Parameters:
signal -
Throws:
java.io.IOException
SshException

channelRequest

protected void channelRequest(java.lang.String requesttype,
                              boolean wantreply,
                              byte[] requestdata)
                       throws SshException
This overidden method handles the "exit-status", "exit-signal" and "xon-xoff" channel requests.

Overrides:
channelRequest in class Ssh2Channel
Parameters:
requesttype - the name of the request
wantreply - specifies whether the remote side requires a success/failure message
requestdata - the request data
Throws:
SshException

exitCode

public int exitCode()
Description copied from interface: SshSession
Return the exit code of the process once complete. Call this after the session has been closed to obtain the exit code of the process. It MAY or MAY NOT be sent by the server. If the exit code was not received this method will return EXITCODE_NOT_RECEIVED.

Specified by:
exitCode in interface SshSession
Returns:
the exit code value or SshSession.EXITCODE_NOT_RECEIVED

hasExitSignal

public boolean hasExitSignal()
Determine whether the remote process was signalled.

Returns:
true if a signal was received, otherwise false

getExitSignalInfo

public java.lang.String getExitSignalInfo()
Get the exit signal information, may be an empty string.

Returns:


Copyright © 2003 3SP LTD. All Rights Reserved.