pub struct Channel { /* private fields */ }
Expand description
Handle to an SSH channel (low level API).
Use this object to send requests and data to the server over an SSH channel. To receive events
and data from the server, use the matching ChannelReceiver
. To obtain an instance of
Channel
and ChannelReceiver
, use the method Client::open_channel()
.
This is part of a low level API that gives you direct access to an SSH channel, as
described in RFC 4254, section 5. If you want to execute programs, consider using a
Session
, which provides an API that hides the details of the SSH protocol.
You can cheaply clone this object and safely share the clones between tasks.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn send_request(&self, req: ChannelReq) -> Result<()>
pub fn send_request(&self, req: ChannelReq) -> Result<()>
Send a request to the server.
This sends a SSH_MSG_CHANNEL_REQUEST
to the channel (RFC 4254, section 5.4). We simply
enqueue the request and immediately return without any blocking, but you may use
ChannelReq::reply_tx
to wait for the reply. Note that requests are not subject to the
SSH flow control mechanism.
Sourcepub async fn send_data(&self, data: Bytes, data_type: DataType) -> Result<()>
pub async fn send_data(&self, data: Bytes, data_type: DataType) -> Result<()>
Send channel data to the server.
This sends a series of SSH_MSG_CHANNEL_DATA
or SSH_MSG_CHANNEL_EXTENDED_DATA
(depending
on data_type
) to the channel (RFC 4254, section 5.2). We may split data
into
multiple packets, subject to the SSH flow control mechanism and maximum packet size.
This method returns after all bytes have been accepted by the flow control mechanism and written to the internal send buffer, but before we send them to the socket (or other I/O stream that backs this SSH connection).
Sourcepub async fn send_eof(&self) -> Result<()>
pub async fn send_eof(&self) -> Result<()>
Send end-of-file marker to the server.
This sends SSH_MSG_CHANNEL_EOF
to the channel (RFC 4254, section 5.3) to signify that you
will not send any more data to this channel.
This method returns after all bytes previously sent to this channel have been accepted by the flow control mechanism, but before we write the message to the socket (or other I/O stream that backs this SSH connection).
If the channel is closed before you call this method, or if it closes before this method
returns, we quietly ignore this error and return Ok
.
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Close the channel.
This sends SSH_MSG_CHANNEL_CLOSE
to the channel (RFC 4254, section 5.3) and the channel
will become closed after we receive the same message from the server. We won’t send any
further requests or data to the server.
This method is idempotent: if the channel is already closed or closing, we do nothing.