forked from 1148118271/ssh-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
31 lines (27 loc) · 1.03 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
fn main() {
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than INFO (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::INFO)
// completes the builder.
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let mut session = ssh::create_session()
.username("ubuntu")
.password("password")
.private_key_path("./id_rsa")
.connect("127.0.0.1:22")
.unwrap()
.run_local();
let exec = session.open_exec().unwrap();
let vec: Vec<u8> = exec.send_command("ls -all").unwrap();
println!("{}", String::from_utf8(vec).unwrap());
// Close session.
let exec = session.open_exec().unwrap();
let vec: Vec<u8> = exec.send_command("no_command").unwrap();
println!("{}", String::from_utf8(vec).unwrap());
session.close();
}