Skip to main content

SshClient

Struct SshClient 

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

Core SSH client structure

Implementations§

Source§

impl SshClient

Source

pub async fn connect_authenticated( &mut self, config: &ConnectionConfig<'_>, ) -> Result<Client>

Establish an authenticated SSH transport without closing it after one operation.

Connection multiplexing keeps the returned client in the control master and opens one channel per attached invocation. Callers own the transport lifetime and must invoke crate::ssh::tokio_client::Client::disconnect exactly once when the master terminates.

Source

pub async fn connect_and_forward_stdio( &mut self, target: (String, u16), config: &ConnectionConfig<'_>, ) -> Result<()>

Connect and expose a remote direct-tcpip channel on local stdio.

This is intentionally separate from command/session execution: -W creates no session channel, PTY, RemoteCommand, or command timeout.

Source

pub async fn connect_and_execute( &mut self, command: &str, key_path: Option<&Path>, use_agent: bool, ) -> Result<CommandResult>

Execute a command on the remote host with basic configuration

Source

pub async fn connect_and_execute_with_host_check( &mut self, command: &str, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, timeout_seconds: Option<u64>, ssh_password: Option<Arc<Password>>, ) -> Result<CommandResult>

Execute a command with host key checking configuration.

The ssh_password argument carries the dispatcher’s single up-front password (when --password is used). Callers in the download glob-resolution path MUST forward FileTransferParams::ssh_password here — otherwise the user is prompted twice (once by the dispatcher, once by this connection).

Source

pub async fn connect_and_execute_with_jump_hosts( &mut self, command: &str, config: &ConnectionConfig<'_>, ) -> Result<CommandResult>

Execute a command with full configuration including jump hosts

Source

pub async fn connect_and_execute_with_output_streaming( &mut self, command: &str, config: &ConnectionConfig<'_>, output_sender: Sender<CommandOutput>, ) -> Result<u32>

Execute a command with streaming output support

This method provides real-time command output streaming through the provided sender channel. Output is sent as CommandOutput::StdOut or CommandOutput::StdErr variants.

§Arguments
  • command - The command to execute
  • config - Connection configuration
  • output_sender - Channel sender for streaming output
§Returns

The exit status of the command

Source

pub async fn connect_and_execute_with_output_streaming_and_stdin( &mut self, command: &str, config: &ConnectionConfig<'_>, output_sender: Sender<CommandOutput>, ) -> Result<u32>

Execute a command with byte-transparent stdout/stderr and piped stdin.

Source

pub async fn connect_and_execute_with_sudo( &mut self, command: &str, config: &ConnectionConfig<'_>, output_sender: Sender<CommandOutput>, sudo_password: &SudoPassword, ) -> Result<u32>

Execute a command with sudo password support and streaming output.

This method handles automatic sudo password injection when sudo prompts are detected in the command output.

§Arguments
  • command - The command to execute (typically uses sudo)
  • config - Connection configuration
  • output_sender - Channel sender for streaming output
  • sudo_password - The sudo password to inject when prompted
§Returns

The exit status of the command

Source§

impl SshClient

Source

pub fn new(host: String, port: u16, username: String) -> Self

Creates a new SSH client instance

Source§

impl SshClient

Source

pub async fn upload_file( &mut self, local_path: &Path, remote_path: &str, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, connect_timeout_seconds: Option<u64>, ) -> Result<()>

Upload a single file to the remote host

Source

pub async fn download_file( &mut self, remote_path: &str, local_path: &Path, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, connect_timeout_seconds: Option<u64>, ) -> Result<()>

Download a single file from the remote host

Source

pub async fn upload_dir( &mut self, local_dir_path: &Path, remote_dir_path: &str, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, connect_timeout_seconds: Option<u64>, ) -> Result<()>

Upload a directory to the remote host

Source

pub async fn download_dir( &mut self, remote_dir_path: &str, local_dir_path: &Path, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, connect_timeout_seconds: Option<u64>, ) -> Result<()>

Download a directory from the remote host

Source

pub async fn upload_file_with_jump_hosts( &mut self, local_path: &Path, remote_path: &str, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, jump_hosts_spec: Option<&str>, connect_timeout_seconds: Option<u64>, pre_collected_password: Option<Arc<Password>>, ssh_connection_config: &SshConnectionConfig, ssh_connection_config_resolver: Option<&SshConnectionConfigResolver>, ) -> Result<()>

Upload file with jump host support

Source

pub async fn download_file_with_jump_hosts( &mut self, remote_path: &str, local_path: &Path, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, jump_hosts_spec: Option<&str>, connect_timeout_seconds: Option<u64>, pre_collected_password: Option<Arc<Password>>, ssh_connection_config: &SshConnectionConfig, ssh_connection_config_resolver: Option<&SshConnectionConfigResolver>, ) -> Result<()>

Download file with jump host support

Source

pub async fn upload_dir_with_jump_hosts( &mut self, local_dir_path: &Path, remote_dir_path: &str, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, jump_hosts_spec: Option<&str>, connect_timeout_seconds: Option<u64>, pre_collected_password: Option<Arc<Password>>, ssh_connection_config: &SshConnectionConfig, ssh_connection_config_resolver: Option<&SshConnectionConfigResolver>, ) -> Result<()>

Upload directory with jump host support

Source

pub async fn download_dir_with_jump_hosts( &mut self, remote_dir_path: &str, local_dir_path: &Path, key_path: Option<&Path>, strict_mode: Option<StrictHostKeyChecking>, use_agent: bool, use_password: bool, jump_hosts_spec: Option<&str>, connect_timeout_seconds: Option<u64>, pre_collected_password: Option<Arc<Password>>, ssh_connection_config: &SshConnectionConfig, ssh_connection_config_resolver: Option<&SshConnectionConfigResolver>, ) -> Result<()>

Download directory with jump host support

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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