pub struct SshShell { /* private fields */ }
Expand description
Represents a connection via SSH to a particular source.
Implementations§
source§impl SshShell
impl SshShell
sourcepub fn with_default_key<A: ToSocketAddrs>(
username: &str,
remote: A
) -> Result<Self, Error>
pub fn with_default_key<A: ToSocketAddrs>(
username: &str,
remote: A
) -> Result<Self, Error>
Returns a shell connected via the default private key at $HOME/.ssh/id_rsa
to the given
SSH server as the given user.
SshShell::with_default_key("markm", "myhost:22")?;
sourcepub fn with_key<A: ToSocketAddrs, P: AsRef<Path>>(
username: &str,
remote: A,
key: P
) -> Result<Self, Error>
pub fn with_key<A: ToSocketAddrs, P: AsRef<Path>>(
username: &str,
remote: A,
key: P
) -> Result<Self, Error>
Returns a shell connected via private key file key
to the given SSH server as the given
user.
SshShell::with_key("markm", "myhost:22", "/home/foo/.ssh/id_rsa")?;
sourcepub fn toggle_dry_run(&mut self)
pub fn toggle_dry_run(&mut self)
Toggles dry run mode. In dry run mode, commands are not executed remotely; we only print what commands we would execute. Note that we do connect remotely, though. This is off by default: we default to actually running the commands.
sourcepub fn reconnect(&mut self) -> Result<(), Error>
pub fn reconnect(&mut self) -> Result<(), Error>
Attempt to reconnect to the remote until it reconnects (possibly indefinitely).
sourcepub fn run(&self, cmd: SshCommand) -> Result<SshOutput, Error>
pub fn run(&self, cmd: SshCommand) -> Result<SshOutput, Error>
Run a command on the remote machine, blocking until the command completes.
Note that command using sudo
will hang indefinitely if sudo
asks for a password.
sourcepub fn spawn(&self, cmd: SshCommand) -> Result<SshSpawnHandle, Error>
pub fn spawn(&self, cmd: SshCommand) -> Result<SshSpawnHandle, Error>
Run a command on the remote machine, without blocking until the command completes. A handle
is returned, which one can join
on to wait for process completion.
Note that command using sudo
will hang indefinitely if sudo
asks for a password.