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;
}
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.

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.