Crate ssh_rs[][src]

Expand description

Dependencies

ssh-rs = "*"

Quick example:

shell

use std::io::{stdin, stdout, Write};
use std::time;
use ssh_rs::SSH;

fn main() {
    let ssh = SSH::new();
    let mut session = ssh.get_session("192.168.3.101:22").unwrap();
    session.set_nonblocking(true).unwrap();
    session.set_user_and_password("root".to_string(), "123456".to_string());
    session.connect().unwrap();
    let mut channel = session.open_channel().unwrap();
    let mut shell = channel.open_shell().unwrap();

    // thread::sleep(time::Duration::from_millis(500));
    // let result = shell.read().unwrap();
    // println!("{}", String::from_utf8(result).unwrap());
    // shell.write(b"ll \n").unwrap();
    // shell.write(b"ll \r").unwrap();
    // thread::sleep(time::Duration::from_millis(500));
    // let result = shell.read().unwrap();
    // println!("{}", String::from_utf8(result).unwrap());
    // shell.close().unwrap();
    // session.close().unwrap();

    loop {
        thread::sleep(time::Duration::from_millis(200));
        let result = shell.read().unwrap();
        stdout().write(result.as_slice()).unwrap();
        stdout().flush();
        let mut cm = String::new();
        stdin().read_line(&mut cm).unwrap();
        shell.write(cm.as_bytes()).unwrap();
    }

}
exec
use ssh_rs::SSH;

fn main() {
    let ssh = SSH::new();
    let mut session = ssh.get_session("192.168.3.101:22").unwrap();
    session.set_user_and_password("root".to_string(), "123456".to_string());
    session.connect().unwrap();
    let mut channel = session.open_channel().unwrap();
    let mut exec = channel.open_exec().unwrap();
    let vec = exec.set_command("ps -ef |grep ssh").unwrap();
    println!("{}", String::from_utf8(vec).unwrap());
    session.close().unwrap();
}

Modules

Structs