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
Sessionimplementation.
-
-
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 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
Modifier and Type Method Description voidallocateDefaultPTY()Allocates a default PTY.voidallocatePTY(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.BooleancanDoFlowControl()Whether the client can do local flow control usingcontrol-Sandcontrol-Q.voidchangeWindowDimensions(int cols, int rows, int width, int height)Sends a window dimension change message.protected voidcloseAllStreams()Called when all I/O streams should be closed.protected voideofInputStreams()Called when EOF has been received.Session.Commandexec(java.lang.String command)Execute a remote command.java.io.InputStreamgetErrorStream()Returns the command'sstderrstream.java.lang.StringgetExitErrorMessage()If the command exit violentlywith a signal, an error message would have been received and can be retrieved via this method.SignalgetExitSignal()Returns thesignalif the command exit violently, ornullif this information was not received.java.lang.IntegergetExitStatus()Returns the exit status of the command if it was received, ornullif this information was not received.java.lang.BooleangetExitWasCoreDumped()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 voidgotExtendedData(SSHPacket buf)voidhandleRequest(java.lang.String req, SSHPacket buf)voidnotifyError(SSHException error)Notifies this object of anerror.voidreqX11Forwarding(java.lang.String authProto, java.lang.String authCookie, int screen)Request X11 forwarding.voidsetEnvVar(java.lang.String name, java.lang.String value)Set an environment variable.voidsignal(Signal sig)Send a signal to the remote command.Session.ShellstartShell()Request a shell.Session.SubsystemstartSubsystem(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
-
-
-
-
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, TransportExceptionDescription copied from interface:SessionAllocates a default PTY. The default PTY is"vt100"with the echo modes disabled.- Specified by:
allocateDefaultPTYin interfaceSession- Throws:
ConnectionExceptionTransportException
-
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, TransportExceptionDescription copied from interface:SessionAllocate a psuedo-terminal for this session.0dimension parameters will be ignored by the server.- Specified by:
allocatePTYin interfaceSession- Parameters:
term-TERMenvironment 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:
ConnectionExceptionTransportException
-
canDoFlowControl
public java.lang.Boolean canDoFlowControl()
Description copied from interface:Session.ShellWhether the client can do local flow control usingcontrol-Sandcontrol-Q.- Specified by:
canDoFlowControlin interfaceSession.Shell- Returns:
- boolean value indicating whether 'client can do', or
nullif no such information was received
-
changeWindowDimensions
public void changeWindowDimensions(int cols, int rows, int width, int height) throws TransportExceptionDescription copied from interface:Session.ShellSends a window dimension change message.- Specified by:
changeWindowDimensionsin 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:SessionExecute a remote command.- Specified by:
execin interfaceSession- Returns:
Session.Commandinstance 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.CommandReturns the command'sstderrstream.- Specified by:
getErrorStreamin interfaceSession.Command- Specified by:
getErrorStreamin interfaceSession.Shell
-
getExitErrorMessage
public java.lang.String getExitErrorMessage()
Description copied from interface:Session.CommandIf 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:
getExitErrorMessagein interfaceSession.Command
-
getExitSignal
public Signal getExitSignal()
Description copied from interface:Session.CommandReturns thesignalif the command exit violently, ornullif this information was not received. NOTE: Always callChannel.close()first before inspecting the exit signal.- Specified by:
getExitSignalin interfaceSession.Command
-
getExitStatus
public java.lang.Integer getExitStatus()
Description copied from interface:Session.CommandReturns the exit status of the command if it was received, ornullif this information was not received. NOTE: Always callChannel.close()first before inspecting the exit status.- Specified by:
getExitStatusin interfaceSession.Command- Specified by:
getExitStatusin interfaceSession.Subsystem
-
handleRequest
public void handleRequest(java.lang.String req, SSHPacket buf) throws ConnectionException, TransportException- Overrides:
handleRequestin classAbstractChannel- Throws:
ConnectionExceptionTransportException
-
reqX11Forwarding
public void reqX11Forwarding(java.lang.String authProto, java.lang.String authCookie, int screen) throws ConnectionException, TransportExceptionDescription copied from interface:SessionRequest X11 forwarding.- Specified by:
reqX11Forwardingin 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, TransportExceptionDescription copied from interface:SessionSet an environment variable.- Specified by:
setEnvVarin 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.CommandSend a signal to the remote command.- Specified by:
signalin interfaceSession.Command- Specified by:
signalin 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:SessionRequest a shell.- Specified by:
startShellin interfaceSession- Returns:
Session.Shellinstance 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:SessionRequest a subsystem.- Specified by:
startSubsystemin interfaceSession- Parameters:
name- subsystem name- Returns:
Session.Subsysteminstance 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.CommandIf 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:
getExitWasCoreDumpedin interfaceSession.Command
-
closeAllStreams
protected void closeAllStreams()
Description copied from class:AbstractChannelCalled when all I/O streams should be closed. Subclasses can override but must call super.- Overrides:
closeAllStreamsin classAbstractChannel
-
eofInputStreams
protected void eofInputStreams()
Description copied from class:AbstractChannelCalled when EOF has been received. Subclasses can override but must call super.- Overrides:
eofInputStreamsin classAbstractChannel
-
gotExtendedData
protected void gotExtendedData(SSHPacket buf) throws SSHException
- Overrides:
gotExtendedDatain classAbstractChannel- Throws:
SSHException
-
notifyError
public void notifyError(SSHException error)
Description copied from interface:ErrorNotifiableNotifies this object of anerror.- Specified by:
notifyErrorin interfaceErrorNotifiable- Overrides:
notifyErrorin classAbstractChannel
-
-