Top Description Fields Methods
org.apache.sshd.client.channel

public Interface ClientChannel

extends Channel, StreamingChannel, ClientSessionHolder
Known Direct Implementers
org.apache.sshd.client.channel.AbstractClientChannel
Imports
java.io.IOException, .InputStream, .OutputStream, java.rmi.RemoteException, .ServerException, java.time.Duration, java.util.Collection, .Set, org.apache.sshd.client.future.OpenFuture, org.apache.sshd.client.session.ClientSession, .ClientSessionHolder, org.apache.sshd.common.SshConstants, org.apache.sshd.common.channel.Channel, .StreamingChannel, org.apache.sshd.common.io.IoInputStream, .IoOutputStream

A client channel used to communicate with the SSH server. Client channels can be shells, simple commands or subsystems

Note

client channels may be associated with a server session if they are opened by the server - e.g., for agent proxy, port forwarding, etc..

Author
Apache MINA SSHD Project

Field Summary

Inherited from org.apache.sshd.common.channel.Channel:
CHANNEL_EXECCHANNEL_SHELLCHANNEL_SUBSYSTEM

Method Summary

Modifier and TypeMethod and Description
public IoInputStream
public IoOutputStream
public IoInputStream
public Set<ClientChannelEvent>

Returns:

A snapshot of the current channel state
getChannelState
()

public String

Returns:

The type of channel reported when it was created
getChannelType
()

public default ClientSession
public String

Returns:

The signaled exit signal via "exit-signal" - null if not signaled
getExitSignal
()

public Integer

Returns:

The signaled exit status via "exit-status" request - null if not signaled
getExitStatus
()

public InputStream

Returns:

an InputStream for reading received data, or null if an output stream was set via setErr(OutputStream)
getInvertedErr
()

Obtains an InputStream to read received SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data directly from the channel.

public OutputStream

Returns:

an OutputStream for sending data, or null if an input stream was set via setIn(InputStream)
getInvertedIn
()

Obtains an OutputStream to send data directly to the remote end of the channel.

public InputStream

Returns:

an InputStream for reading received data, or null if an output stream was set via setOut(OutputStream)
getInvertedOut
()

Obtains an InputStream to read received SshConstants#SSH_MSG_CHANNEL_DATA data directly from the channel.

public OpenFuture
open()

public void
setErr(OutputStream err)

Sets an output stream for the channel to write received SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data to.

public void
setIn(InputStream
an InputStream to be polled and forwarded
in
)

Sets an InputStream that will be read by this channel and forwarded to the remote channel.

public void
setOut(OutputStream out)

Sets an output stream for the channel to write received SshConstants#SSH_MSG_CHANNEL_DATA data to.

public void
setRedirectErrorStream(boolean
whether to redirect the error stream to the output stream.
redirectErrorStream
)

Defines whether to redirect the error stream into the output stream; has no effect if setErr(OutputStream) has also been called by the time the channel is opened.

public static void
validateCommandExitStatusCode(String
The command string - used only for exception text
command
,
Integer
The exit status value
exitStatus
)

Makes sure remote command exit status has been provided and it is zero

public Set<ClientChannelEvent>

Returns:

The actual signaled event - includes ClientChannelEvent#TIMEOUT if timeout expired before the expected event was signaled
waitFor
(Collection<ClientChannelEvent> mask, long
The timeout to wait (msec.) - if non-positive then forever
timeout
)

Waits until any of the specified events in the mask is signaled

public default Set<ClientChannelEvent>

Returns:

The actual signaled event - includes ClientChannelEvent#TIMEOUT if timeout expired before the expected event was signaled
waitFor
(Collection<ClientChannelEvent> mask, Duration
The timeout to wait - if null then forever
timeout
)

Waits until any of the specified events in the mask is signaled

Inherited from org.apache.sshd.common.channel.Channel:
addRequestHandleraddRequestHandlersgetLocalWindowgetRecipientgetRemoteWindowgetRequestHandlershandleChannelRegistrationResulthandleChannelUnregistrationhandleClosehandleDatahandleEofhandleExtendedDatahandleFailurehandleOpenFailurehandleOpenSuccesshandleRequesthandleSuccesshandleWindowAdjustinitisEofSignalledisInitializedopenremoveRequestHandlerremoveRequestHandlersresolveAttributeresolveAttributewritePacket
Inherited from org.apache.sshd.common.channel.StreamingChannel:
getStreamingsetStreaming

Method Detail

getAsyncErrback to summary
public IoInputStream getAsyncErr()
getAsyncInback to summary
public IoOutputStream getAsyncIn()
getAsyncOutback to summary
public IoInputStream getAsyncOut()
getChannelStateback to summary
public Set<ClientChannelEvent> getChannelState()
Returns:Set<ClientChannelEvent>

A snapshot of the current channel state

See Also
waitFor(Collection, long)
getChannelTypeback to summary
public String getChannelType()
Returns:String

The type of channel reported when it was created

getClientSessionback to summary
public default ClientSession getClientSession()

Implements org.apache.sshd.client.session.ClientSessionHolder.getClientSession.

Returns:ClientSession

Doc from org.apache.sshd.client.session.ClientSessionHolder.getClientSession.

The underlying ClientSession used

Annotations
@Override
getExitSignalback to summary
public String getExitSignal()
Returns:String

The signaled exit signal via "exit-signal" - null if not signaled

getExitStatusback to summary
public Integer getExitStatus()
Returns:Integer

The signaled exit status via "exit-status" request - null if not signaled

getInvertedErrback to summary
public InputStream getInvertedErr()

Obtains an InputStream to read received SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data directly from the channel. This is an alternative to setErr(OutputStream). If the error stream is redirected to the output stream via setRedirectErrorStream(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:InputStream

an InputStream for reading received data, or null if an output stream was set via setErr(OutputStream)

See Also
setErr(OutputStream), setRedirectErrorStream(boolean)
getInvertedInback to summary
public OutputStream getInvertedIn()

Obtains an OutputStream to send data directly to the remote end of the channel. This can be used instead of using setIn(InputStream) method and having the channel polling for data in that stream.

When the channel closes, it will close the returned stream.

This method should be called only after the channel has been opened.

Returns:OutputStream

an OutputStream for sending data, or null if an input stream was set via setIn(InputStream)

See Also
setIn(InputStream)
getInvertedOutback to summary
public InputStream getInvertedOut()

Obtains an InputStream to read received SshConstants#SSH_MSG_CHANNEL_DATA data directly from the channel. This is an alternative to setOut(OutputStream). If the error stream is redirected to the output stream via setRedirectErrorStream(true), this stream will also receive SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data.

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:InputStream

an InputStream for reading received data, or null if an output stream was set via setOut(OutputStream)

See Also
setOut(OutputStream), setRedirectErrorStream(boolean)
openback to summary
public OpenFuture open() throws IOException
setErrback to summary
public void setErr(OutputStream err)

Sets an output stream for the channel to write received SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data to. For remote command execution, this is typically the remote command's stderr.

The stream must be set before the channel is opened. When the channel closes, it will close the 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 InputStream obtained via getInvertedErr(). (Or it might forward the data to the output stream if setRedirectErrorStream(true) is set.)

Parameters
err:OutputStream

the OutputStream

See Also
getInvertedErr(), setRedirectErrorStream(boolean)
setInback to summary
public void setIn(InputStream in)

Sets an InputStream that 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 the getInvertedIn() method instead and write data directly.

The stream must be set before the channel is opened. When the channel closes, it will close the given stream. If the stream should not be closed (for instance, if it is System.in), wrap it in an NoCloseInputStream.

Parameters
in:InputStream

an InputStream to be polled and forwarded

See Also
getInvertedIn()
setOutback to summary
public void setOut(OutputStream out)

Sets an output stream for the channel to write received SshConstants#SSH_MSG_CHANNEL_DATA data to. For remote command execution, this is typically the remote command's stdout. If the error stream is redirected to the output stream via setRedirectErrorStream(true), this stream will also receive SshConstants#SSH_MSG_CHANNEL_EXTENDED_DATA data.

The stream must be set before the channel is opened. When the channel closes, it will close the 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 InputStream obtained via getInvertedOut().

Parameters
out:OutputStream

the OutputStream

See Also
getInvertedOut(), setRedirectErrorStream(boolean)
setRedirectErrorStreamback to summary
public void setRedirectErrorStream(boolean redirectErrorStream)

Defines whether to redirect the error stream into the output stream; has no effect if setErr(OutputStream) has also been called by the time the channel is opened.

Parameters
redirectErrorStream:boolean

whether to redirect the error stream to the output stream.

validateCommandExitStatusCodeback to summary
public static void validateCommandExitStatusCode(String command, Integer exitStatus) throws RemoteException

Makes sure remote command exit status has been provided and it is zero

Parameters
command:String

The command string - used only for exception text

exitStatus:Integer

The exit status value

Exceptions
RemoteException:
If exitStatus is null or non-zero
waitForback to summary
public Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, long timeout)

Waits until any of the specified events in the mask is signaled

Parameters
mask:Collection<ClientChannelEvent>

The ClientChannelEvents mask

timeout:long

The timeout to wait (msec.) - if non-positive then forever

Returns:Set<ClientChannelEvent>

The actual signaled event - includes ClientChannelEvent#TIMEOUT if timeout expired before the expected event was signaled

waitForback to summary
public default Set<ClientChannelEvent> waitFor(Collection<ClientChannelEvent> mask, Duration timeout)

Waits until any of the specified events in the mask is signaled

Parameters
mask:Collection<ClientChannelEvent>

The ClientChannelEvents mask

timeout:Duration

The timeout to wait - if null then forever

Returns:Set<ClientChannelEvent>

The actual signaled event - includes ClientChannelEvent#TIMEOUT if timeout expired before the expected event was signaled