pub struct SshClient { /* private fields */ }Implementations§
Source§impl SshClient
impl SshClient
pub fn new(host_keys: Arc<HostKeyStore>) -> Self
pub async fn connect(&mut self, config: &SshConfig) -> Result<()>
Sourcepub async fn execute_command(&self, command: &str) -> Result<String>
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.
Sourcepub async fn execute_command_full(&self, command: &str) -> Result<CommandOutput>
pub async fn execute_command_full(&self, command: &str) -> Result<CommandOutput>
Execute a remote command and return full stdout/stderr/exit-code.
Sourcepub async fn execute_command_streaming(
&self,
command: &str,
) -> Result<(Receiver<String>, CancellationToken)>
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.
pub async fn disconnect(&mut self) -> Result<()>
Sourcepub async fn open_direct_tcpip(
&self,
host: &str,
port: u16,
) -> Result<Channel<Msg>>
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.
Sourcepub async fn create_pty_session(
&self,
cols: u32,
rows: u32,
) -> Result<PtySession>
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.
pub async fn list_dir(&self, path: &str) -> Result<Vec<RemoteFileEntry>>
pub async fn download_file( &self, remote_path: &str, local_path: &str, ) -> Result<u64>
Sourcepub async fn download_file_with_progress(
&self,
remote_path: &str,
local_path: &str,
progress: impl FnMut(u64),
cancel: Option<&CancellationToken>,
) -> Result<u64>
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).
pub async fn download_file_to_memory( &self, remote_path: &str, ) -> Result<Vec<u8>>
pub async fn upload_file( &self, local_path: &str, remote_path: &str, ) -> Result<u64>
Sourcepub async fn upload_file_with_progress(
&self,
local_path: &str,
remote_path: &str,
progress: impl FnMut(u64),
cancel: Option<&CancellationToken>,
) -> Result<u64>
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).
pub async fn upload_file_from_bytes( &self, data: &[u8], remote_path: &str, ) -> Result<u64>
Sourcepub async fn create_dir(&self, path: &str) -> Result<()>
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.
Sourcepub async fn rename(&self, old_path: &str, new_path: &str) -> Result<()>
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.
Sourcepub async fn delete_file(&self, path: &str) -> Result<()>
pub async fn delete_file(&self, path: &str) -> Result<()>
Delete a regular file. For directories, use delete_dir.
Sourcepub async fn delete_dir(&self, path: &str) -> Result<()>
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).