#ssh-client #thrussh #high-level #mio #built

yanked thrussh_client

A high-level SSH client built with Thrussh and Mio

Uses old Rust 2015

0.5.0 Jul 22, 2016
0.4.0 Jul 21, 2016
0.3.3 Jul 20, 2016
0.2.0 Jul 12, 2016
0.1.0 Jul 1, 2016

#11 in #thrussh


Used in thrussh_scp

Apache-2.0

21KB
419 lines

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();
}

Dependencies

~23MB
~226K SLoC