AsyncSession

Struct AsyncSession 

Source
pub struct AsyncSession<H: Handler> { /* private fields */ }
Expand description

An SSH session, which may open multiple AsyncChannels.

This struct is a thin wrapper around russh::client::Handle which provides basic authentication and channel management for a SSH session. Implements Deref to allow access to the underlying russh::client::Handle.

Implementations§

Source§

impl<H: 'static + Handler> AsyncSession<H>

Source

pub async fn open_sftp(&self) -> Result<SftpSession, SshOrSftpError>

Available on crate feature sftp only.

Opens an SFTP channel.

Equivalent to AsyncSession::open_channel() followed by requesting the SFTP subsystem:

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

impl<H: 'static + Handler> AsyncSession<H>

Source

pub async fn connect_unauthenticated( config: Arc<Config>, addrs: impl ToSocketAddrs, handler: H, ) -> Result<Self, H::Error>

Connect to an SSH server using the provided configuration and handler, without beginning authentication.

Source

pub async fn open_channel(&self) -> Result<AsyncChannel, SshError>

Opens an AsyncChannel in this session.

AsyncChannel is the asnyc wrapper for russh::Channel.

Source§

impl AsyncSession<NoCheckHandler>

Source

pub async fn connect_publickey( config: impl Into<Arc<Config>>, addrs: impl ToSocketAddrs, user: impl Into<String>, key_path: impl AsRef<Path>, ) -> Result<Self, SshError>

Connect to an SSH server and authenticate with the given user and key_path via publickey authentication.

Uses NoCheckHandler to skip server public key verification, as publickey authentication provides protection against MITM attacks.

Methods from Deref<Target = Handle<H>>§

Source

pub fn is_closed(&self) -> bool

Source

pub async fn best_supported_rsa_hash( &self, ) -> Result<Option<Option<HashAlg>>, Error>

Returns the best RSA hash algorithm supported by the server, as indicated by the server-sig-algs extension. If the server does not support the extension, None is returned. In this case you may still attempt an authentication with rsa-sha2-256 or rsa-sha2-512 and hope for the best. If the server supports the extension, but does not support rsa-sha2-*, Some(None) is returned.

Note that this method will wait for up to 1 second for the server to send the extension info if it hasn’t done so yet (except when running under WebAssembly). Unfortunately the timing of the EXT_INFO message cannot be known in advance (RFC 8308).

If this method returns None once, then for most SSH servers you can assume that it will return None every time.

Source

pub async fn channel_open_session(&self) -> Result<Channel<Msg>, Error>

Request a session channel (the most basic type of channel). This function returns Some(..) immediately if the connection is authenticated, but the channel only becomes usable when it’s confirmed by the server, as indicated by the confirmed field of the corresponding Channel.

Source

pub async fn channel_open_x11<A>( &self, originator_address: A, originator_port: u32, ) -> Result<Channel<Msg>, Error>
where A: Into<String>,

Request an X11 channel, on which the X11 protocol may be tunneled.

Source

pub async fn channel_open_direct_tcpip<A, B>( &self, host_to_connect: A, port_to_connect: u32, originator_address: B, originator_port: u32, ) -> Result<Channel<Msg>, Error>
where A: Into<String>, B: Into<String>,

Open a TCP/IP forwarding channel. This is usually done when a connection comes to a locally forwarded TCP/IP port. See RFC4254. The TCP/IP packets can then be tunneled through the channel using .data(). After writing a stream to a channel using .data(), be sure to call .eof() to indicate that no more data will be sent, or you may see hangs when writing large streams.

Source

pub async fn channel_open_direct_streamlocal<S>( &self, socket_path: S, ) -> Result<Channel<Msg>, Error>
where S: Into<String>,

Source

pub async fn cancel_tcpip_forward<A>( &self, address: A, port: u32, ) -> Result<(), Error>
where A: Into<String>,

Source

pub async fn cancel_streamlocal_forward<A>( &self, socket_path: A, ) -> Result<(), Error>
where A: Into<String>,

Source

pub async fn disconnect( &self, reason: Disconnect, description: &str, language_tag: &str, ) -> Result<(), Error>

Sends a disconnect message.

Source

pub async fn data( &self, id: ChannelId, data: CryptoVec, ) -> Result<(), CryptoVec>

Send data to the session referenced by this handler.

This is useful for server-initiated channels; for channels created by the client, prefer to use the Channel returned from the open_* methods.

Source

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

Asynchronously perform a session re-key at the next opportunity

Source

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

Send a keepalive package to the remote peer.

Trait Implementations§

Source§

impl<H: Handler> Deref for AsyncSession<H>

Source§

type Target = Handle<H>

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl<H> Freeze for AsyncSession<H>

§

impl<H> !RefUnwindSafe for AsyncSession<H>

§

impl<H> Send for AsyncSession<H>

§

impl<H> Sync for AsyncSession<H>

§

impl<H> Unpin for AsyncSession<H>

§

impl<H> !UnwindSafe for AsyncSession<H>

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