thrussh_client 0.5.0

A high-level SSH client built with Thrussh and Mio.

This is an SSH client library, designed to read configuration files in the same format as OpenSSH.

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::Client::new();
    client.set_host("localhost");
    client.default_ssh_config().unwrap();
    let mut client = client.connect().unwrap();
    if let Some(key) = client.authenticate().unwrap() {
        client.learn_host(&key).unwrap();
        assert!(client.authenticate().unwrap().is_none());
    }

    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 channel0 = client.channel_open_session().unwrap();
    client.wait_channel_open(&mut c, channel0).unwrap();
    client.exec(channel0, false, "ls -l");
    client.eof(channel0);

    let channel1 = client.channel_open_session().unwrap();
    client.wait_channel_open(&mut c, channel1).unwrap();
    client.data(channel1, None, b"blabla blibli").unwrap();
    client.eof(channel1);
    client.close(channel1);

    client.wait_channel_close(&mut c, channel0).unwrap();
}