Crate thrussh_client [] [src]

extern crate thrussh_client;
extern crate env_logger;
use thrussh_client::*;
use std::io::Write;

fn main() {
    env_logger::init().unwrap();
    let mut client = thrussh_client::SSHClient::new("localhost", 22).unwrap();
    let key = thrussh_client::load_secret_key("/home/pe/.ssh/id_ed25519").unwrap();
    client.session().set_auth_public_key("pe".to_string(), key);
    client.authenticate().unwrap();

    struct C;
    impl thrussh_client::Handler for C {
        fn data(&mut self,
                _: u32,
                _: Option<u32>,
                data: &[u8],
                _: &mut Session)
                -> Result<(), Error> {
            try!(std::io::stdout().write(data));
            Ok(())
        }
    }
    let mut c = C;
    let channel = client.session().channel_open_session().unwrap();
    client.wait_channel_open(&mut c, channel).unwrap();
    client.session().exec(channel, false, "ls -l");
    client.session().eof(channel);
    client.wait_channel_close(&mut c, channel).unwrap();
}

Structs

Basic
SSHClient
Session

Enums

Error

Traits

Handler

Functions

load_secret_key

Load a secret key from a file. Only ed25519 keys are currently supported.