Skip to main content

SshClient

Struct SshClient 

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

Implementations§

Source§

impl SshClient

Source

pub fn new(host_keys: Arc<HostKeyStore>) -> Self

Source

pub async fn connect(&mut self, config: &SshConfig) -> Result<()>

Source

pub async fn execute_command(&self, command: &str) -> Result<String>

Execute a remote command and return the combined stdout+stderr as a string, matching the shell-convention where both streams are interleaved in the user’s view. Returns Err only for transport-level failures (session gone, channel couldn’t open) — a nonzero exit code is a valid result, not an error, and its stdout/stderr is still returned.

For callers that need to branch on the exit code or separate streams, use SshClient::execute_command_full instead.

Source

pub async fn execute_command_full(&self, command: &str) -> Result<CommandOutput>

Execute a remote command and return full stdout/stderr/exit-code.

Source

pub async fn execute_command_streaming( &self, command: &str, ) -> Result<(Receiver<String>, CancellationToken)>

Execute a remote command and stream its stdout line-by-line over an mpsc channel. Returns the receiver and a cancellation token — dropping the receiver or cancelling the token tears down the channel.

Used by long-running tools like tcpdump where the caller wants real-time line output instead of waiting for the command to exit. stderr lines are sent on the same channel prefixed with "!" so the consumer can distinguish them; the convention keeps the FFI surface a single string stream.

Source

pub async fn disconnect(&mut self) -> Result<()>

Source

pub async fn open_direct_tcpip( &self, host: &str, port: u16, ) -> Result<Channel<Msg>>

Open a direct-tcpip channel that the SSH server bridges to (host, port) as seen from the server’s network. Used by the Postgres tunnel to forward a local TCP listener through this SSH session.

originator_address/originator_port are reported to the server for logging/auditing and may be 127.0.0.1:0 when the caller doesn’t have a meaningful client endpoint to advertise.

Source

pub async fn create_pty_session( &self, cols: u32, rows: u32, ) -> Result<PtySession>

Create a persistent PTY shell session (like ttyd) This enables interactive commands like vim, less, more, top, etc.

Source

pub async fn list_dir(&self, path: &str) -> Result<Vec<RemoteFileEntry>>

Source

pub async fn download_file( &self, remote_path: &str, local_path: &str, ) -> Result<u64>

Source

pub async fn download_file_with_progress( &self, remote_path: &str, local_path: &str, progress: impl FnMut(u64), cancel: Option<&CancellationToken>, ) -> Result<u64>

Stream a remote file to disk, calling progress after every SFTP chunk with the running total of bytes transferred. Caller is responsible for knowing the file’s total size — use list_dir / the entry’s size field beforehand.

The callback runs synchronously inside the read loop, so it must be cheap. The macOS bridge uses it to emit TransferProgress events on the event bus; the real work happens on the consumer thread that drains the bus, not here.

cancel, when supplied, is checked between chunks. On cancellation the partial local file is left on disk (callers can delete it on receipt of the TransferCancelled error if they want clean removal — leaving it lets a future “resume” feature pick up where we left off).

Source

pub async fn download_file_to_memory( &self, remote_path: &str, ) -> Result<Vec<u8>>

Source

pub async fn upload_file( &self, local_path: &str, remote_path: &str, ) -> Result<u64>

Source

pub async fn upload_file_with_progress( &self, local_path: &str, remote_path: &str, progress: impl FnMut(u64), cancel: Option<&CancellationToken>, ) -> Result<u64>

Stream a local file to the remote, calling progress after every SFTP chunk. See download_file_with_progress for the threading constraints — the callback is on the same task as the SFTP I/O.

cancel checks between chunks; on cancellation the partial remote file is left in place (call delete_file afterwards if clean removal is wanted).

Source

pub async fn upload_file_from_bytes( &self, data: &[u8], remote_path: &str, ) -> Result<u64>

Source

pub async fn create_dir(&self, path: &str) -> Result<()>

Create a directory on the remote. Fails if the parent doesn’t exist or the path is already taken.

Source

pub async fn rename(&self, old_path: &str, new_path: &str) -> Result<()>

Rename a file or directory. SFTP RENAME is atomic when source and destination are on the same filesystem; cross-filesystem renames may copy-then-delete depending on the server.

Source

pub async fn delete_file(&self, path: &str) -> Result<()>

Delete a regular file. For directories, use delete_dir.

Source

pub async fn delete_dir(&self, path: &str) -> Result<()>

Delete an empty directory. SFTP requires the directory be empty; recursive removal would need a list-then-delete loop, which belongs at the caller layer (with progress reporting).

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