Interface ClientChannel
- All Superinterfaces:
AttributeRepository,AttributeStore,AutoCloseable,Channel,Channel,ChannelIdentifier,ChannelListenerManager,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,ClientSessionHolder,Closeable,Closeable,PropertyResolver,SessionContextHolder,SessionHolder<Session>,StreamingChannel
- All Known Implementing Classes:
AbstractClientChannel,AgentForwardedChannel,ChannelDirectTcpip,ChannelExec,ChannelForwardedX11,ChannelSession,ChannelShell,ChannelSubsystem,DefaultSftpClient.SftpChannelSubsystem,PtyCapableChannelSession,TcpipClientChannel
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface org.apache.sshd.common.channel.StreamingChannel
StreamingChannel.Streaming -
Field Summary
Fields inherited from interface org.apache.sshd.common.channel.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMFields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Method Summary
Modifier and TypeMethodDescriptiondefault ClientSessionObtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata directly from the channel.Obtains anOutputStreamto send data directly to the remote end of the channel.Obtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_DATAdata directly from the channel.open()voidsetErr(OutputStream err) Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata to.voidsetIn(InputStream in) Sets anInputStreamthat will be read by this channel and forwarded to the remote channel.voidsetOut(OutputStream out) Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_DATAdata to.voidsetRedirectErrorStream(boolean redirectErrorStream) Defines whether to redirect the error stream into the output stream; has no effect ifsetErr(OutputStream)has also been called by the time the channel is opened.static voidvalidateCommandExitStatusCode(String command, Integer exitStatus) Makes sure remote command exit status has been provided and it is zerowaitFor(Collection<ClientChannelEvent> mask, long timeout) Waits until any of the specified events in the mask is signaleddefault Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, Duration timeout) Waits until any of the specified events in the mask is signaledMethods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface org.apache.sshd.common.channel.Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleOpenFailure, handleOpenSuccess, handleRequest, handleSuccess, handleWindowAdjust, init, isEofSignalled, isInitialized, open, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacketMethods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelIdMethods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSession, getSessionContextMethods inherited from interface org.apache.sshd.common.channel.StreamingChannel
getStreaming, setStreaming
-
Method Details
-
getClientSession
- Specified by:
getClientSessionin interfaceClientSessionHolder- Returns:
- The underlying
ClientSessionused
-
getChannelType
String getChannelType()- Returns:
- The type of channel reported when it was created
-
getAsyncIn
IoOutputStream getAsyncIn() -
getAsyncOut
IoInputStream getAsyncOut() -
getAsyncErr
IoInputStream getAsyncErr() -
getInvertedIn
OutputStream getInvertedIn()Obtains anOutputStreamto send data directly to the remote end of the channel. This can be used instead of usingsetIn(InputStream)method and having the channel polling for data in that stream.When the channel closes, it will
closethe returned stream.This method should be called only after the channel has been opened.
- Returns:
- an
OutputStreamfor sending data, ornullif an input stream was set viasetIn(InputStream) - See Also:
-
getInvertedOut
InputStream getInvertedOut()Obtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_DATAdata directly from the channel. This is an alternative tosetOut(OutputStream). If the error stream is redirected to the output stream viasetRedirectErrorStream(true), this stream will also receiveSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata.When the channel closes, it will not close the returned stream. It is the caller's responsibility to close the returned stream if needed. Closing the stream while the channel is open may cause the channel to be closed forcibly if more data arrives. The stream remains open after the channel has closed, so that the caller can read the last arrived data even afterwards.
As with all external processes, the application should read this stream to avoid that the channel blocks when the stream's buffer is full. The buffer size for the returned stream is bounded by the channel's local window size. If the caller does not read this stream, the channel will block once the local window is exhausted.
This method should be called only after the channel has been opened.
- Returns:
- an
InputStreamfor reading received data, ornullif an output stream was set viasetOut(OutputStream) - See Also:
-
getInvertedErr
InputStream getInvertedErr()Obtains anInputStreamto read receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata directly from the channel. This is an alternative tosetErr(OutputStream). If the error stream is redirected to the output stream viasetRedirectErrorStream(true), the returned stream will not receive any data and be always at EOF.When the channel closes, it will not close the returned stream. It is the caller's responsibility to close the returned stream if needed. Closing the stream while the channel is open may cause the channel to be closed forcibly if more data arrives. The stream remains open after the channel has closed, so that the caller can read the last arrived data even afterwards.
As with all external processes, the application should read this stream (unless it was redirected) to avoid that the channel blocks when the stream's buffer is full. The buffer size for the returned stream is bounded by the channel's local window size. If the caller does not read this stream, the channel will block once the local window is exhausted.
This method should be called only after the channel has been opened.
- Returns:
- an
InputStreamfor reading received data, ornullif an output stream was set viasetErr(OutputStream) - See Also:
-
setIn
Sets anInputStreamthat will be read by this channel and forwarded to the remote channel. Note that using such a stream will create an additional thread for pumping the stream which will only be able to end when that stream is actually closed or EOF on the stream is reached. It is recommended to use thegetInvertedIn()method instead and write data directly.The stream must be set before the channel is opened. When the channel closes, it will
closethe given stream.- Parameters:
in- anInputStreamto be polled and forwarded- See Also:
-
setOut
Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_DATAdata to. For remote command execution, this is typically the remote command'sstdout. If the error stream is redirected to the output stream viasetRedirectErrorStream(true), this stream will also receiveSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata.The stream must be set before the channel is opened. When the channel closes, it will
closethe given stream.If no stream is set by the time the channel is opened, the channel will internally forward data to a stream that can be read via the
InputStreamobtained viagetInvertedOut().- Parameters:
out- theOutputStream- See Also:
-
setErr
Sets an output stream for the channel to write receivedSshConstants.SSH_MSG_CHANNEL_EXTENDED_DATAdata to. For remote command execution, this is typically the remote command'sstderr.The stream must be set before the channel is opened. When the channel closes, it will
closethe given stream.If no stream is set by the time the channel is opened, the channel will internally forward data to a stream that can be read via the
InputStreamobtained viagetInvertedErr(). (Or it might forward the data to the output stream ifsetRedirectErrorStream(true)is set.)- Parameters:
err- theOutputStream- See Also:
-
setRedirectErrorStream
void setRedirectErrorStream(boolean redirectErrorStream) Defines whether to redirect the error stream into the output stream; has no effect ifsetErr(OutputStream)has also been called by the time the channel is opened.- Parameters:
redirectErrorStream- whether to redirect the error stream to the output stream.
-
open
- Throws:
IOException
-
getChannelState
Set<ClientChannelEvent> getChannelState()- Returns:
- A snapshot of the current channel state
- See Also:
-
waitFor
Waits until any of the specified events in the mask is signaled- Parameters:
mask- TheClientChannelEvents masktimeout- The timeout to wait (msec.) - if non-positive then forever- Returns:
- The actual signaled event - includes
ClientChannelEvent.TIMEOUTif timeout expired before the expected event was signaled
-
waitFor
Waits until any of the specified events in the mask is signaled- Parameters:
mask- TheClientChannelEvents masktimeout- The timeout to wait - if null then forever- Returns:
- The actual signaled event - includes
ClientChannelEvent.TIMEOUTif timeout expired before the expected event was signaled
-
getExitStatus
Integer getExitStatus()- Returns:
- The signaled exit status via "exit-status" request -
nullif not signaled
-
getExitSignal
String getExitSignal()- Returns:
- The signaled exit signal via "exit-signal" -
nullif not signaled
-
validateCommandExitStatusCode
static void validateCommandExitStatusCode(String command, Integer exitStatus) throws RemoteException Makes sure remote command exit status has been provided and it is zero- Parameters:
command- The command string - used only for exception textexitStatus- The exit status value- Throws:
RemoteException- If exitStatus isnullor non-zero
-