```rust fn main() { let ssh: SSH = SSH::new(); // enable logging ssh.enablelog(true).unwrap(); let mut session = ssh.getsession("127.0.0.1:22").unwrap(); session.setuserandpassword("root".tostring(), "123456".tostring()); session.connect().unwrap(); exec(&mut session); shell(&mut session); // tshell(&mut session); }
fn exec(session: &mut Session) { let exec: ChannelExec = session.openexec().unwrap(); let vec = exec.sendcommand("ls -all").unwrap(); println!("{}", String::from_utf8(vec).unwrap()); }
fn shell(session: &mut Session) { let mut shell = session.openshell().unwrap(); thread::sleep(time::Duration::frommillis(200)); let vec = shell.read().unwrap(); let result = String::fromutf8(vec).unwrap(); println!("{}", result); shell.write(b"ls -a\r").unwrap(); thread::sleep(time::Duration::frommillis(200)); let vec = shell.read().unwrap(); let result = String::from_utf8(vec).unwrap(); println!("{}", result); shell.close().unwrap(); }
fn tshell(session: &mut Session) { let shell = session.openshell().unwrap(); let c1 = Arc::new(Mutex::new(shell)); let c2 = Arc::clone(&c1); let t1 = thread::spawn( move || { loop { let x = c1.lock().unwrap().read().unwrap(); if x.isempty() { continue } stdout().write(x.asslice()).unwrap(); stdout().flush().unwrap(); } });
let t2 = thread::spawn( move || {
loop {
let mut cm = String::new();
stdin().read_line(&mut cm).unwrap();
c2.lock().unwrap().write(cm.as_bytes()).unwrap();
}
});
t1.join().unwrap();
t2.join().unwrap();
}
```
| algorithms | is supported |
|-------------------------------|---------------|
| curve25519-sha256 | √ |
| ecdh-sha2-nistp256 | √ |
| ssh-ed25519 | √ |
| rsa | √ |
| chacha20-poly1305@openssh.com | √ |
| user auth | is supported |
|------------------|--------------|
| publickey | × |
| password | √ |
| hostbased | × |
| channel | is supported |
|-----------|---------------|
| shell | √ |
| exec | √ |
| subsystem | × |