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>
impl<H: 'static + Handler> AsyncSession<H>
Sourcepub async fn open_sftp(&self) -> Result<SftpSession, SshOrSftpError>
Available on crate feature sftp only.
pub async fn open_sftp(&self) -> Result<SftpSession, SshOrSftpError>
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>
impl<H: 'static + Handler> AsyncSession<H>
Sourcepub async fn connect_unauthenticated(
config: Arc<Config>,
addrs: impl ToSocketAddrs,
handler: H,
) -> Result<Self, H::Error>
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.
Sourcepub async fn open_channel(&self) -> Result<AsyncChannel, SshError>
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>
impl AsyncSession<NoCheckHandler>
Sourcepub async fn connect_publickey(
config: impl Into<Arc<Config>>,
addrs: impl ToSocketAddrs,
user: impl Into<String>,
key_path: impl AsRef<Path>,
) -> Result<Self, SshError>
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>>§
pub fn is_closed(&self) -> bool
Sourcepub async fn best_supported_rsa_hash(
&self,
) -> Result<Option<Option<HashAlg>>, Error>
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.
Sourcepub async fn channel_open_session(&self) -> Result<Channel<Msg>, Error>
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.
Sourcepub async fn channel_open_x11<A>(
&self,
originator_address: A,
originator_port: u32,
) -> Result<Channel<Msg>, Error>
pub async fn channel_open_x11<A>( &self, originator_address: A, originator_port: u32, ) -> Result<Channel<Msg>, Error>
Request an X11 channel, on which the X11 protocol may be tunneled.
Sourcepub 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>
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>
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.
pub async fn channel_open_direct_streamlocal<S>( &self, socket_path: S, ) -> Result<Channel<Msg>, Error>
pub async fn cancel_tcpip_forward<A>( &self, address: A, port: u32, ) -> Result<(), Error>
pub async fn cancel_streamlocal_forward<A>( &self, socket_path: A, ) -> Result<(), Error>
Sourcepub async fn disconnect(
&self,
reason: Disconnect,
description: &str,
language_tag: &str,
) -> Result<(), Error>
pub async fn disconnect( &self, reason: Disconnect, description: &str, language_tag: &str, ) -> Result<(), Error>
Sends a disconnect message.
Sourcepub async fn data(
&self,
id: ChannelId,
data: CryptoVec,
) -> Result<(), CryptoVec>
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.
Sourcepub async fn rekey_soon(&self) -> Result<(), Error>
pub async fn rekey_soon(&self) -> Result<(), Error>
Asynchronously perform a session re-key at the next opportunity