AsyncChannel

Struct AsyncChannel 

Source
pub struct AsyncChannel { /* private fields */ }
Expand description

An asynchronous SSH channel, one of possibly many within a single SSH AsyncSession. Each channel represents a separate command, shell, SFTP session, X11 forwarding, or other SSH subsystem.

This struct is a thin wrapper around russh::Channel which provides access to async read/write streams (stdout/stderr/stdin) and async event handling Implements Deref to allow access to the underlying russh::ChannelWriteHalf.

§Shutdown Lifecycle

During shutdown, events may be received in the following order. However this should not be relied upon, as the order may be different and none of these events are guaranteed to occur, except for Self::wait_close which will always happen last.

  1. Self::recv_success_failure.
  2. Self::recv_eof - Guarantees all stream data has been received, i.e. stdout/stderr will produce no more data. Channels may be closed without sending EOF; see this StackOverflow answer.
  3. Self::recv_exit_status - The exit status of the command run, if applicable.
  4. Self::wait_close - This channel is closed, no more events will occur.

Implementations§

Source§

impl AsyncChannel

Source

pub async fn sftp(&self) -> Result<SftpSession, SftpError>

Available on crate feature sftp only.

Starst an SFTP session on this channel.

Make sure this channel was opened with AsyncSession::open_sftp, or if not, make sure to request the SFTP subsystem before calling this:

channel.request_subsystem(true, "sftp").await.unwrap();
Source§

impl AsyncChannel

Source

pub fn read_stream(&self, ext: Option<u32>) -> ReadStream

Returns the specified stream as a ReadStream.

Note that the returned stream will only receive data after this call, so call this before calling exec.

When this is called for the same ext more than once, the later call will disconnect the first.

Source

pub fn stdout(&self) -> ReadStream

Returns stdout as a ReadStream.

Note that the returned stream will only receive data after this call, so call this before calling exec.

When this is called more than once, the later call will disconnect the first.

Source

pub fn stderr(&self) -> ReadStream

Returns stderr as a ReadStream.

Note that the returned stream will only receive data after this call, so call this before calling exec.

When this is called more than once, the later call will disconnect the first.

Source

pub fn write_stream(&self, ext: Option<u32>) -> impl AsyncWrite

Returns the specified stream as an impl AsyncWrite.

When this is called for the same ext more than once, writes to each may be interleaved.

Source

pub fn stdin(&self) -> impl AsyncWrite

Returns stdin as an impl AsyncWrite.

When this is called more than once, writes to each may be interleaved.

Source

pub fn recv_success_failure(&self) -> &Promise<bool>

Resolves when success or failure has been received, where true indicates success.

Source

pub fn recv_eof(&self) -> &Promise<()>

Resolves when EOF has been received, indicating all stream data is complete.

At that point, any streams from Self::stdout/Self::stderr/Self::read_stream will return no additional data.

Source

pub fn recv_exit_status(&self) -> &Promise<u32>

Resolves when the command exit status has been received.

Source

pub async fn wait_close(&mut self)

Returns when the channel has been closed.

After this point, no more events will resolve.

Source

pub fn is_closed(&self) -> bool

Returns if the channel has been closed. See Self::wait_close.

Methods from Deref<Target = ChannelWriteHalf<Msg>>§

Source

pub async fn writable_packet_size(&self) -> usize

Returns the min between the maximum packet size and the remaining window size in the channel.

Source

pub fn id(&self) -> ChannelId

Source

pub async fn request_pty( &self, want_reply: bool, term: &str, col_width: u32, row_height: u32, pix_width: u32, pix_height: u32, terminal_modes: &[(Pty, u32)], ) -> Result<(), Error>

Request a pseudo-terminal with the given characteristics.

Source

pub async fn request_shell(&self, want_reply: bool) -> Result<(), Error>

Request a remote shell.

Source

pub async fn exec<A>(&self, want_reply: bool, command: A) -> Result<(), Error>
where A: Into<Vec<u8>>,

Execute a remote program (will be passed to a shell). This can be used to implement scp (by calling a remote scp and tunneling to its standard input).

Source

pub async fn signal(&self, signal: Sig) -> Result<(), Error>

Signal a remote process.

Source

pub async fn request_subsystem<A>( &self, want_reply: bool, name: A, ) -> Result<(), Error>
where A: Into<String>,

Request the start of a subsystem with the given name.

Source

pub async fn request_x11<A, B>( &self, want_reply: bool, single_connection: bool, x11_authentication_protocol: A, x11_authentication_cookie: B, x11_screen_number: u32, ) -> Result<(), Error>
where A: Into<String>, B: Into<String>,

Request X11 forwarding through an already opened X11 channel. See RFC4254 for security issues related to cookies.

Source

pub async fn set_env<A, B>( &self, want_reply: bool, variable_name: A, variable_value: B, ) -> Result<(), Error>
where A: Into<String>, B: Into<String>,

Set a remote environment variable.

Source

pub async fn window_change( &self, col_width: u32, row_height: u32, pix_width: u32, pix_height: u32, ) -> Result<(), Error>

Inform the server that our window size has changed.

Source

pub async fn agent_forward(&self, want_reply: bool) -> Result<(), Error>

Inform the server that we will accept agent forwarding channels

Source

pub async fn data<R>(&self, data: R) -> Result<(), Error>
where R: AsyncRead + Unpin,

Send data to a channel.

Source

pub async fn extended_data<R>(&self, ext: u32, data: R) -> Result<(), Error>
where R: AsyncRead + Unpin,

Send data to a channel. The number of bytes added to the “sending pipeline” (to be processed by the event loop) is returned.

Source

pub async fn eof(&self) -> Result<(), Error>

Source

pub async fn exit_status(&self, exit_status: u32) -> Result<(), Error>

Source

pub async fn close(&self) -> Result<(), Error>

Request that the channel be closed.

Source

pub fn make_writer(&self) -> impl AsyncWrite

Make a writer for the Channel to send ChannelMsg::Data through the AsyncWrite trait.

Source

pub fn make_writer_ext(&self, ext: Option<u32>) -> impl AsyncWrite

Make a writer for the Channel to send ChannelMsg::Data or ChannelMsg::ExtendedData depending on the ext parameter, through the AsyncWrite trait.

Trait Implementations§

Source§

impl Deref for AsyncChannel

Source§

type Target = ChannelWriteHalf<Msg>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Channel<Msg>> for AsyncChannel

Source§

fn from(inner: Channel<Msg>) -> Self

Converts to this type from the input type.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more