Comments (1)
Here is a simple quick & dirty example:
use std::net::TcpStream;
use async_io::Async;
use async_std::task;
use async_std::net::ToSocketAddrs;
use async_std::io::ReadExt;
use async_ssh2::Session;
fn main() {
task::block_on(async {
// Connect to the local SSH server
let addr = "127.0.0.1:22".to_socket_addrs().await
.unwrap()
.next()
.unwrap();
let tcp = Async::<TcpStream>::connect(addr).await.unwrap();
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp).unwrap();
sess.handshake().await.unwrap();
sess.userauth_password("username", "password").await.unwrap();
let mut channel = sess.channel_session().await.unwrap();
println!("Executing");
channel.exec("sleep 90").await.unwrap();
let mut s = String::new();
channel.read_to_string(&mut s).await.unwrap();
println!("{}", s);
channel.wait_close().await.unwrap();
let exit_sig = channel.exit_signal().unwrap();
println!("Signal: {:?} Message: {:?}", exit_sig.exit_signal, exit_sig.error_message);
});
}
If I run that and then kill the spawned 'sleep 90' command from another terminal, it prints this:
Signal: Some("TERM") Message: None
If I let it run to completion, I get this:
Signal: None Message: None
from async-ssh2.
Related Issues (14)
- Build fails HOT 1
- Q: How to forward data to a local tcp server? HOT 3
- Blocking on stream.read_to_string() HOT 3
- Build fails HOT 1
- libssh2 multiple channels concurrent issue
- Listener::accept() tight loops
- Rationale for deprecation? HOT 6
- Enhance Session to support Jumpbox
- session.set_tcp_stream HOT 10
- LIBSSH2_AGENT doesn't implement Send HOT 9
- Thread blocks on sess.handshake() HOT 13
- waking up concurrent reads on the same session HOT 1
- Segfault in Session::userauth_agent() HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-ssh2.