The telnetlib Module

The telnetlib module provides a telnet client implementation.

Example 7-31 connects to a Unix computer, logs in, and then retrieves a directory listing.

Example 7-31. Using the telnetlib Module to Log In to a Remote Server


import telnetlib
import sys

HOST = "spam.egg"

USER = "mulder"
PASSWORD = "trustno1"

telnet = telnetlib.Telnet(HOST)

telnet.read_until("login: ")
telnet.write(USER + "

telnet.read_until("Password: ")
telnet.write(PASSWORD + "

telnet.write("ls librarybook

print telnet.read_all()

[spam.egg mulder]$ ls

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols


Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh © 2008-2020.
If you may any questions please contact us: