Skip to main content

SshClientTrait

Trait SshClientTrait 

Source
pub trait SshClientTrait:
    Send
    + Sync
    + 'static {
    // Required methods
    fn connect<'async_trait>(
        cfg: ConnectionConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Box<Self>, SshCliError>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;
    fn run_command<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        cmd: &'life1 str,
        max_chars: usize,
        stdin_data: Option<Vec<u8>>,
    ) -> Pin<Box<dyn Future<Output = Result<ExecutionOutput, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn upload<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        local: &'life1 Path,
        remote: &'life2 Path,
    ) -> Pin<Box<dyn Future<Output = Result<TransferResult, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn download<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        remote: &'life1 Path,
        local: &'life2 Path,
    ) -> Pin<Box<dyn Future<Output = Result<TransferResult, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn open_tunnel_channel<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        remote_host: &'life1 str,
        remote_port: u16,
        origin_addr: &'life2 str,
        origin_port: u16,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn TunnelChannel>, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn disconnect<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn open_streamlocal_channel<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _socket_path: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn TunnelChannel>, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn request_remote_forward<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _address: &'life1 str,
        _port: u16,
    ) -> Pin<Box<dyn Future<Output = Result<u16, SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn cancel_remote_forward<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _address: &'life1 str,
        _port: u16,
    ) -> Pin<Box<dyn Future<Output = Result<(), SshCliError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn accept_forwarded_channel<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<Box<dyn TunnelChannel>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

SSH client trait allowing a real (russh) or mock implementation for tests.

Abstracts SSH connection operations so unit tests can run without a real network.

Required Methods§

Source

fn connect<'async_trait>( cfg: ConnectionConfig, ) -> Pin<Box<dyn Future<Output = Result<Box<Self>, SshCliError>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Connects to an SSH server and authenticates with the provided credentials.

Source

fn run_command<'life0, 'life1, 'async_trait>( &'life0 mut self, cmd: &'life1 str, max_chars: usize, stdin_data: Option<Vec<u8>>, ) -> Pin<Box<dyn Future<Output = Result<ExecutionOutput, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs a remote shell command and returns the captured output.

stdin_data, if present, is written to the channel after exec and before the loop read loop (GAP-SSH-SEC-001: sudo/su password stays off the remote argv).

Source

fn upload<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, local: &'life1 Path, remote: &'life2 Path, ) -> Pin<Box<dyn Future<Output = Result<TransferResult, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Uploads a local file to the remote server via SCP.

Source

fn download<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, remote: &'life1 Path, local: &'life2 Path, ) -> Pin<Box<dyn Future<Output = Result<TransferResult, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Downloads a remote file to the local filesystem via SCP.

Source

fn open_tunnel_channel<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, remote_host: &'life1 str, remote_port: u16, origin_addr: &'life2 str, origin_port: u16, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn TunnelChannel>, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Opens a direct-tcpip channel for tunnel forwarding.

Source

fn disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cleanly closes the SSH connection.

Provided Methods§

Source

fn open_streamlocal_channel<'life0, 'life1, 'async_trait>( &'life0 self, _socket_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn TunnelChannel>, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Opens a direct-streamlocal@openssh.com channel to a remote Unix socket.

Defaulted to “unsupported” rather than made mandatory: mock and stub clients genuinely cannot forward a Unix socket, and forcing every one of them to hand-write the same refusal only adds places for the refusal to drift.

§Errors

SshCliError::ChannelFailed — always, for clients without streamlocal.

Source

fn request_remote_forward<'life0, 'life1, 'async_trait>( &'life0 self, _address: &'life1 str, _port: u16, ) -> Pin<Box<dyn Future<Output = Result<u16, SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Requests a server-side listener, returning the port the server bound.

§Errors

SshCliError::ChannelFailed — always, for clients without reverse forwarding.

Source

fn cancel_remote_forward<'life0, 'life1, 'async_trait>( &'life0 self, _address: &'life1 str, _port: u16, ) -> Pin<Box<dyn Future<Output = Result<(), SshCliError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancels a server-side listener previously requested.

§Errors

SshCliError::ChannelFailed — always, for clients without reverse forwarding.

Source

fn accept_forwarded_channel<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<Box<dyn TunnelChannel>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Waits for the next channel opened by the server on an active reverse forward.

None means no further channels can arrive, which ends the accept loop.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl SshClientTrait for SshClient

Available on crate feature ssh-real only.