telnet functionality

Ben btjenkins at
Tue Jun 4 10:22:41 EDT 2002

I am trying to write a script that combines telnet, FTP, and gzip
functionalities.  Here is the process: open telnet connection, change
to new directory, list directory, grab last file in directory (the
file most recently added), and append it to a list.  Then, close the
telnet connection and open an FTP connection and place the list I
created in a folder specified by user (through FTP connection).  I
will then use gzip to open file and perform other actions.

Initially, I designed this to work with FTP only, but the project has
changed and I need to add telnet functionality.  I have worked with
the script to the point where I can open a telnet account, change to
new directory, and list the directory's contents...but, I can't seem
to figure out how to grab the last file in the directory and append it
to the list.  It seems that telnetlib doesn't offer that ability.

Here is what I am working with currently:
from ftplib import FTP
import getpass
import string, sys
import telnetlib
import gzip

HOST = sys.argv[1]
user = sys.argv[2]
password = sys.argv[3]
pw = 'sample'
tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.read_until('$' )
tn.write(pw + "\n")
tn.write('cd /home/dir\n')

#flist = []                     # I used these lines from my previous
#sdr = []

print tn.read_all()


Any help would be greatly appreciated.  My efforts to find advice has
not been very successful to date.

Thank you, in advance.

- Ben

More information about the Python-list mailing list