pub async fn launch(opts: LaunchOpts<'_>) -> LuaResult<Self> {
        trace!("Session::launch({:?})", opts);
        let LaunchOpts {
            host,
            mode,
            handler,
            ssh,
            distant,
            timeout,
        } = opts;

        // First, establish a connection to an SSH server
        debug!("Connecting to {} {:#?}", host, ssh);
        let mut ssh_session = Ssh2Session::connect(host.as_str(), ssh).to_lua_err()?;

        // Second, authenticate with the server
        debug!("Authenticating against {}", host);
        ssh_session.authenticate(handler).await.to_lua_err()?;

        // Third, convert our ssh session into a distant session based on desired method
        debug!("Mapping session for {} into {:?}", host, mode);
        let session = match mode {
            Mode::Distant => ssh_session
                .into_distant_session(IntoDistantSessionOpts {
                    binary: distant.bin,
                    args: distant.args,
                    use_login_shell: distant.use_login_shell,
                    timeout,
                })
                .await
                .to_lua_err()?,
            Mode::Ssh => ssh_session.into_ssh_client_session().await.to_lua_err()?,
        };

        // Fourth, store our current session in our global map and then return a reference
        let id = utils::rand_u32()? as usize;
        debug!("Session {} established against {}", id, host);
        SESSION_MAP
            .write()
            .map_err(|x| x.to_string().to_lua_err())?
            .insert(id, session);
        Ok(Self::new(id))
    }
/// Launches a new distant session on a remote machine
Launches a new distant session on a remote machine
Launches a new distant session on a remote machine
pub async fn launch(opts: LaunchOpts<'_>) -> LuaResult<Self> {
        trace!("Session::launch({:?})", opts);
        let LaunchOpts {
            host,
            mode,
            handler,
            ssh,
            distant,
            timeout,
        } = opts;
        // First, establish a connection to an SSH server
        debug!("Connecting to {} {:#?}", host, ssh);
        let mut ssh_session = Ssh2Session::connect(host.as_str(), ssh).to_lua_err()?;
        // Second, authenticate with the server
        debug!("Authenticating against {}", host);
        ssh_session.authenticate(handler).await.to_lua_err()?;
        // Third, convert our ssh session into a distant session based on desired method
        debug!("Mapping session for {} into {:?}", host, mode);
        let session = match mode {
            Mode::Distant => ssh_session
                .into_distant_session(IntoDistantSessionOpts {
                    binary: distant.bin,
                    args: distant.args,
                    use_login_shell: distant.use_login_shell,
                    timeout,
                })
                .await
                .to_lua_err()?,
            Mode::Ssh => ssh_session.into_ssh_client_session().await.to_lua_err()?,
        };
        // Fourth, store our current session in our global map and then return a reference
        let id = utils::rand_u32()? as usize;
        debug!("Session {} established against {}", id, host);
        SESSION_MAP
            .write()
            .map_err(|x| x.to_string().to_lua_err())?
            .insert(id, session);
        Ok(Self::new(id))
    }
pub async fn launch ( opts : LaunchOpts < ' _ > ) -> LuaResult < Self > { trace ! ( " " opts ) ; let LaunchOpts { host , mode , handler , ssh , distant , timeout , } = opts ; // First, establish a connection to an SSH server debug ! ( " " host ssh ) ; let mut ssh_session = Ssh2Session :: connect ( host . as_str ( ) , ssh ) . to_lua_err ( ) ? ; // Second, authenticate with the server debug ! ( " " host ) ; ssh_session . authenticate ( handler ) . await . to_lua_err ( ) ? ; // Third, convert our ssh session into a distant session based on desired method debug ! ( " " host mode ) ; let session = match mode { Mode :: Distant => ssh_session . into_distant_session ( IntoDistantSessionOpts { binary : distant . bin , args : distant . args , use_login_shell : distant . use_login_shell , timeout , } ) . await . to_lua_err ( ) ? , Mode :: Ssh => ssh_session . into_ssh_client_session ( ) . await . to_lua_err ( ) ? , } ; // Fourth, store our current session in our global map and then return a reference let id = utils :: rand_u32 ( ) ? as usize ; debug ! ( " " id host ) ; SESSION_MAP . write ( ) . map_err ( | x | x . to_string ( ) . to_lua_err ( ) ) ? . insert ( id , session ) ; Ok ( Self :: new ( id ) ) }
Launches a new distant session on a remote machine
Launches a new distant session on a remote machine
opts
LaunchOpts<'_>