feat: update ssh-rs

This commit is contained in:
2022-09-04 16:54:01 +08:00
parent 338d2720ac
commit 36e1609002
2 changed files with 26 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
use ssh_rs::{Session, ssh};
use std::thread::sleep;
use std::time::Duration;
use ssh_rs::{ChannelShell, Session, ssh};
use ssh_rs::key_pair::KeyPairType;
fn main() {
@@ -16,4 +18,24 @@ fn main() {
let exec = session.open_exec().unwrap();
let v = exec.send_command("ls -l -a --color ~/").unwrap();
println!("{}", String::from_utf8_lossy(&v).to_string());
}
println!("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>");
let mut shell: ChannelShell = session.open_shell().unwrap();
run_shell(&mut shell);
shell.close().ok();
session.close().ok();
}
fn run_shell(shell: &mut ChannelShell) {
sleep(Duration::from_millis(500));
let vec = shell.read().unwrap();
println!("{}", String::from_utf8(vec).unwrap());
shell.write(b"ls\n").unwrap();
sleep(Duration::from_millis(500));
let vec = shell.read().unwrap();
println!("{}", String::from_utf8(vec).unwrap());
}