host.telnet

Telnet client for remote host connections.

TelnetClient handles the transport-level concerns: opening a telnet connection, negotiating protocol options (echo suppression), authenticating, and optionally sending NAWS (window-size) updates on SIGWINCH so remote TUIs reflow like they do under SSH. After login the reader/writer streams are handed off to a TelnetSession for command execution.

class otto.host.telnet.TelnetClient(host, user, password, options=<factory>, prompt=None, connect_port=None)

Bases: object

host : --is-rst--:py:class:`str`
user : --is-rst--:py:class:`str`
password : --is-rst--:py:class:`str`
options : --is-rst--:py:class:`~otto.host.options.TelnetOptions`

Connection options. Default reproduces otto’s historical behavior.

prompt : --is-rst--:py:data:`~typing.Optional`\ \[:py:class:`str`] = None

Shell prompt string the device displays after each command (e.g. ‘$ ‘ or ‘# ‘). Used during login to confirm authentication succeeded.

connect_port : --is-rst--:py:data:`~typing.Optional`\ \[:py:class:`int`] = None

Override port for ConnectionManager’s tunneled case. When None, options.port is used. Keeps tunnel port-forwarding transparent to the TelnetOptions carried through the rest of the stack.

reader : --is-rst--:py:data:`~typing.Any` = None
writer : --is-rst--:py:data:`~typing.Any` = None
async connect(interactive=False)

Open the telnet connection, negotiate options, and log in.

Parameters:

interactive – When True, skip the DONT ECHO negotiation so the remote shell echoes keystrokes back — required for otto.host.interact.run_telnet_login() so the user sees what they type. Non-interactive callers (the default) get DONT ECHO so command echoes don’t mix with captured output.

Return type:

None

async login()

Send credentials through an established telnet stream.

Readiness after the password is not confirmed here. When no prompt is configured, login() returns as soon as the password is written and the session’s marker handshake (otto.host.session.ShellSession._ensure_initialized(), which runs immediately after) is the deterministic readiness check — it reads through any banner/MOTD to a unique sentinel and is bounded by a timeout that surfaces a bad-credential login as a clear error.

Return type:

None

property alive : bool

Whether the underlying TCP transport is still usable.

close() clears writer/reader to None, and the asyncio writer reports is_closing() after a peer-initiated EOF. Either signal means the next read/write would fail, so callers (notably ConnectionManager.telnet()) should treat the client as stale.

async close()

Gracefully close the telnet connection.

Return type:

None