Thursday, May 28, 2020

Rust process to connect ssh via os command

During my rust learning, I wonder to make some application out of my learning. So, thought to make ssh based terminal application so I can use it my daily use.

As I would like to start a small piece of the snippet to make the actual logic to prototype. I began to identify the ssh frameworks that I can utilize in my application.  During that exploration time, I found a shortcut which is easy to achieve at every first level.

The idea is to use the ssh command available in the os. This code is very simple and attracts the rust beginners.

This snippet calling the ssh terminal command and passing the required argument
that is actually my username and server host.
use std::process::Command;

fn main() {
    let username = "<Fillup>";
    let hostname = "<Fillup>";
    let cmd_out = Command::new("ssh")
        .arg(format!("{}@{}",username,hostname))
        .output();

    match cmd_out {
        Ok(o) => {
            let l = format!(
                "{}{}",
                String::from_utf8_lossy(&o.stdout),
                String::from_utf8_lossy(&o.stderr)
            );
            if o.status.success() {
                println!("{}", l);
            }
        }
        Err(e) => {
            println!("{}", e);
        }
    }
}

So the question is still open, did I complete the SSH application?

Now it is in WIP, once completed let you know.

No comments:

Post a Comment

Merging two sorted arrays - Big O (n+m) time complexity

 Problem :  Merge the two sorted arrays. Edge case :  Array can empty Arrays can be in different size let getMaxLength = ( input1 , input...