Class SessionChannel
- java.lang.Object
-
- net.schmizz.sshj.connection.channel.AbstractChannel
-
- net.schmizz.sshj.connection.channel.direct.AbstractDirectChannel
-
- net.schmizz.sshj.connection.channel.direct.SessionChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ErrorNotifiable
,SSHPacketHandler
,Channel
,Channel.Direct
,Session
,Session.Command
,Session.Shell
,Session.Subsystem
public class SessionChannel extends AbstractDirectChannel implements Session, Session.Command, Session.Shell, Session.Subsystem
Session
implementation.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.schmizz.sshj.connection.channel.AbstractChannel
AbstractChannel.TransportRunnable
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.connection.channel.Channel
Channel.Direct, Channel.Forwarded
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.common.ErrorNotifiable
ErrorNotifiable.Util
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.connection.channel.direct.Session
Session.Command, Session.Shell, Session.Subsystem
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Boolean
canDoFlowControl
private ChannelInputStream
err
private java.lang.String
exitErrMsg
private Signal
exitSignal
private java.lang.Integer
exitStatus
private boolean
usedUp
private java.lang.Boolean
wasCoreDumped
-
Fields inherited from class net.schmizz.sshj.connection.channel.AbstractChannel
closeEvent, conn, log, loggerFactory, lwin, openEvent, rwin, trans
-
-
Constructor Summary
Constructors Constructor Description SessionChannel(Connection conn)
SessionChannel(Connection conn, java.nio.charset.Charset remoteCharset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allocateDefaultPTY()
Allocates a default PTY.void
allocatePTY(java.lang.String term, int cols, int rows, int width, int height, java.util.Map<PTYMode,java.lang.Integer> modes)
Allocate a psuedo-terminal for this session.java.lang.Boolean
canDoFlowControl()
Whether the client can do local flow control usingcontrol-S
andcontrol-Q
.void
changeWindowDimensions(int cols, int rows, int width, int height)
Sends a window dimension change message.private void
checkReuse()
protected void
closeAllStreams()
Called when all I/O streams should be closed.protected void
eofInputStreams()
Called when EOF has been received.Session.Command
exec(java.lang.String command)
Execute a remote command.java.io.InputStream
getErrorStream()
Returns the command'sstderr
stream.java.lang.String
getExitErrorMessage()
If the command exit violentlywith a signal
, an error message would have been received and can be retrieved via this method.Signal
getExitSignal()
Returns thesignal
if the command exit violently, ornull
if this information was not received.java.lang.Integer
getExitStatus()
Returns the exit status of the command if it was received, ornull
if this information was not received.java.lang.Boolean
getExitWasCoreDumped()
If the command exit violentlywith a signal
, information about whether a core dump took place would have been received and can be retrieved via this method.protected void
gotExtendedData(SSHPacket buf)
void
handleRequest(java.lang.String req, SSHPacket buf)
void
notifyError(SSHException error)
Notifies this object of anerror
.void
reqX11Forwarding(java.lang.String authProto, java.lang.String authCookie, int screen)
Request X11 forwarding.void
setEnvVar(java.lang.String name, java.lang.String value)
Set an environment variable.void
signal(Signal sig)
Send a signal to the remote command.Session.Shell
startShell()
Request a shell.Session.Subsystem
startSubsystem(java.lang.String name)
Request a subsystem.-
Methods inherited from class net.schmizz.sshj.connection.channel.direct.AbstractDirectChannel
buildOpenReq, gotUnknown, open
-
Methods inherited from class net.schmizz.sshj.connection.channel.AbstractChannel
close, finishOff, getAutoExpand, getID, getInputStream, getLocalMaxPacketSize, getLocalWinSize, getLoggerFactory, getOutputStream, getRecipient, getRemoteCharset, getRemoteMaxPacketSize, getRemoteWinSize, getType, handle, init, isEOF, isOpen, join, join, newBuffer, receiveInto, sendChannelRequest, sendClose, setAutoExpand, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.schmizz.sshj.connection.channel.Channel
close, getAutoExpand, getID, getInputStream, getLocalMaxPacketSize, getLocalWinSize, getLoggerFactory, getOutputStream, getRecipient, getRemoteCharset, getRemoteMaxPacketSize, getRemoteWinSize, getType, isEOF, isOpen, join, join, setAutoExpand
-
Methods inherited from interface net.schmizz.sshj.common.SSHPacketHandler
handle
-
-
-
-
Field Detail
-
err
private final ChannelInputStream err
-
exitStatus
private volatile java.lang.Integer exitStatus
-
exitSignal
private volatile Signal exitSignal
-
wasCoreDumped
private volatile java.lang.Boolean wasCoreDumped
-
exitErrMsg
private volatile java.lang.String exitErrMsg
-
canDoFlowControl
private volatile java.lang.Boolean canDoFlowControl
-
usedUp
private boolean usedUp
-
-
Constructor Detail
-
SessionChannel
public SessionChannel(Connection conn)
-
SessionChannel
public SessionChannel(Connection conn, java.nio.charset.Charset remoteCharset)
-
-
Method Detail
-
allocateDefaultPTY
public void allocateDefaultPTY() throws ConnectionException, TransportException
Description copied from interface:Session
Allocates a default PTY. The default PTY is"vt100"
with the echo modes disabled.- Specified by:
allocateDefaultPTY
in interfaceSession
- Throws:
ConnectionException
TransportException
-
allocatePTY
public void allocatePTY(java.lang.String term, int cols, int rows, int width, int height, java.util.Map<PTYMode,java.lang.Integer> modes) throws ConnectionException, TransportException
Description copied from interface:Session
Allocate a psuedo-terminal for this session.0
dimension parameters will be ignored by the server.- Specified by:
allocatePTY
in interfaceSession
- Parameters:
term
-TERM
environment variable value (e.g.,vt100
)cols
- terminal width, cols (e.g., 80)rows
- terminal height, rows (e.g., 24)width
- terminal width, pixels (e.g., 640)height
- terminal height, pixels (e.g., 480)- Throws:
ConnectionException
TransportException
-
canDoFlowControl
public java.lang.Boolean canDoFlowControl()
Description copied from interface:Session.Shell
Whether the client can do local flow control usingcontrol-S
andcontrol-Q
.- Specified by:
canDoFlowControl
in interfaceSession.Shell
- Returns:
- boolean value indicating whether 'client can do', or
null
if no such information was received
-
changeWindowDimensions
public void changeWindowDimensions(int cols, int rows, int width, int height) throws TransportException
Description copied from interface:Session.Shell
Sends a window dimension change message.- Specified by:
changeWindowDimensions
in interfaceSession.Shell
- Parameters:
cols
- terminal width, columnsrows
- terminal height, rowswidth
- terminal width, pixelsheight
- terminal height, pixels- Throws:
TransportException
-
exec
public Session.Command exec(java.lang.String command) throws ConnectionException, TransportException
Description copied from interface:Session
Execute a remote command.- Specified by:
exec
in interfaceSession
- Returns:
Session.Command
instance which should now be used- Throws:
ConnectionException
- if the request to execute the command failedTransportException
- if there is an error sending the request
-
getErrorStream
public java.io.InputStream getErrorStream()
Description copied from interface:Session.Command
Returns the command'sstderr
stream.- Specified by:
getErrorStream
in interfaceSession.Command
- Specified by:
getErrorStream
in interfaceSession.Shell
-
getExitErrorMessage
public java.lang.String getExitErrorMessage()
Description copied from interface:Session.Command
If the command exit violentlywith a signal
, an error message would have been received and can be retrieved via this method. Otherwise, this method will returnnull
. NOTE: Always callChannel.close()
first before inspecting the exit error message.- Specified by:
getExitErrorMessage
in interfaceSession.Command
-
getExitSignal
public Signal getExitSignal()
Description copied from interface:Session.Command
Returns thesignal
if the command exit violently, ornull
if this information was not received. NOTE: Always callChannel.close()
first before inspecting the exit signal.- Specified by:
getExitSignal
in interfaceSession.Command
-
getExitStatus
public java.lang.Integer getExitStatus()
Description copied from interface:Session.Command
Returns the exit status of the command if it was received, ornull
if this information was not received. NOTE: Always callChannel.close()
first before inspecting the exit status.- Specified by:
getExitStatus
in interfaceSession.Command
- Specified by:
getExitStatus
in interfaceSession.Subsystem
-
handleRequest
public void handleRequest(java.lang.String req, SSHPacket buf) throws ConnectionException, TransportException
- Overrides:
handleRequest
in classAbstractChannel
- Throws:
ConnectionException
TransportException
-
reqX11Forwarding
public void reqX11Forwarding(java.lang.String authProto, java.lang.String authCookie, int screen) throws ConnectionException, TransportException
Description copied from interface:Session
Request X11 forwarding.- Specified by:
reqX11Forwarding
in interfaceSession
- Parameters:
authProto
- X11 authentication protocol nameauthCookie
- X11 authentication cookiescreen
- X11 screen number- Throws:
ConnectionException
- if the request failedTransportException
- if there was an error sending the request
-
setEnvVar
public void setEnvVar(java.lang.String name, java.lang.String value) throws ConnectionException, TransportException
Description copied from interface:Session
Set an environment variable.- Specified by:
setEnvVar
in interfaceSession
- Parameters:
name
- name of the variablevalue
- value to set- Throws:
ConnectionException
- if the request failedTransportException
- if there was an error sending the request
-
signal
public void signal(Signal sig) throws TransportException
Description copied from interface:Session.Command
Send a signal to the remote command.- Specified by:
signal
in interfaceSession.Command
- Specified by:
signal
in interfaceSession.Shell
- Parameters:
sig
- the signal- Throws:
TransportException
- if error sending the signal
-
startShell
public Session.Shell startShell() throws ConnectionException, TransportException
Description copied from interface:Session
Request a shell.- Specified by:
startShell
in interfaceSession
- Returns:
Session.Shell
instance which should now be used- Throws:
ConnectionException
- if the request failedTransportException
- if there was an error sending the request
-
startSubsystem
public Session.Subsystem startSubsystem(java.lang.String name) throws ConnectionException, TransportException
Description copied from interface:Session
Request a subsystem.- Specified by:
startSubsystem
in interfaceSession
- Parameters:
name
- subsystem name- Returns:
Session.Subsystem
instance which should now be used- Throws:
ConnectionException
- if the request failedTransportException
- if there was an error sending the request
-
getExitWasCoreDumped
public java.lang.Boolean getExitWasCoreDumped()
Description copied from interface:Session.Command
If the command exit violentlywith a signal
, information about whether a core dump took place would have been received and can be retrieved via this method. Otherwise, this method will returnnull
.- Specified by:
getExitWasCoreDumped
in interfaceSession.Command
-
closeAllStreams
protected void closeAllStreams()
Description copied from class:AbstractChannel
Called when all I/O streams should be closed. Subclasses can override but must call super.- Overrides:
closeAllStreams
in classAbstractChannel
-
eofInputStreams
protected void eofInputStreams()
Description copied from class:AbstractChannel
Called when EOF has been received. Subclasses can override but must call super.- Overrides:
eofInputStreams
in classAbstractChannel
-
gotExtendedData
protected void gotExtendedData(SSHPacket buf) throws SSHException
- Overrides:
gotExtendedData
in classAbstractChannel
- Throws:
SSHException
-
notifyError
public void notifyError(SSHException error)
Description copied from interface:ErrorNotifiable
Notifies this object of anerror
.- Specified by:
notifyError
in interfaceErrorNotifiable
- Overrides:
notifyError
in classAbstractChannel
-
checkReuse
private void checkReuse()
-
-