Telnet

Struct Telnet 

Source
pub struct Telnet { /* private fields */ }

Implementations§

Source§

impl Telnet

Source

pub fn builder() -> TelnetBuilder

Create a TelnetBuilder

Source

pub async fn login( &mut self, username: &str, password: &str, ) -> Result<(), TelnetError>

Login remote telnet daemon, only retry one time.

§Examples
let mut client = Telnet::builder()
    .prompt("username@hostname:$ ")
    .login_prompt("login: ", "Password: ")
    .connect_timeout(Duration::from_secs(3))
    .connect("192.168.0.1:23").await?;

match client.login("username", "password").await {
    Ok(_) => println!("login success."),
    Err(e) => println!("login failed: {}", e),
};
Source

pub async fn execute(&mut self, cmd: &str) -> Result<String, TelnetError>

Execute command, and filter it input message by line count.

§Examples
assert_eq!(telnet.execute("echo 'haha'").await?, "haha\n");
Source

pub async fn normal_execute(&mut self, cmd: &str) -> Result<String, TelnetError>

All echoed content is returned when the command is executed.(Note that this may contain some useless information, such as prompts, which need to be filtered and processed by yourself.)

§Examples
assert_eq!(
    "echo 'haha'\nhaha\n",
    telnet.normal_execute("echo 'haha'").await?
);

Auto Trait Implementations§

§

impl !Freeze for Telnet

§

impl RefUnwindSafe for Telnet

§

impl Send for Telnet

§

impl Sync for Telnet

§

impl Unpin for Telnet

§

impl UnwindSafe for Telnet

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.