Struct Channel

Source
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

Source

pub fn client(&self) -> Client

Get the Client that this channel belongs to.

Source

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.

Source

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).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Channel

Source§

fn clone(&self) -> Channel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V