pub struct Telnet { /* private fields */ }Implementations§
Source§impl Telnet
impl Telnet
Sourcepub fn builder() -> TelnetBuilder
pub fn builder() -> TelnetBuilder
Create a TelnetBuilder
Sourcepub async fn login(
&mut self,
username: &str,
password: &str,
) -> Result<(), TelnetError>
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),
};Sourcepub async fn execute(&mut self, cmd: &str) -> Result<String, TelnetError>
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");Sourcepub async fn normal_execute(&mut self, cmd: &str) -> Result<String, TelnetError>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more