[Tutor] Question

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Oct 27 20:06:01 2002


On Sun, 27 Oct 2002, Gus Tabares wrote:

>     I'm trying to write a script that, when prompted by 'Password: ',
> could automatically enter the password itself. Any lead in the right
> direction would be greatly appreciated. Thanks

Hi Gus,

Traditionally, Unix admin would use a a utility called 'expect' to
automate this kind of password entry.  Expect is written in Tk, and
doesn't have a special relationship with Python.


However, there is a project that's a port of Expect to Python called
'pexpect':

    http://sourceforge.net/projects/pexpect/

The pexpect project page appears to be down at the moment.  Drats.
However, Google has it cached at the moment.  Here's an example that's on
the cached Google page:


###
# This connects to the openbsd ftp site and
# downloads the recursive directory listing.
import pexpect
child = pexpect.spawn ('ftp ftp.openbsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('my@email.com')
child.expect ('ftp> ')
child.sendline ('cd pub')
child.expect('ftp> ')
child.sendline ('get ls-lR.gz')
child.expect('ftp> ')
child.sendline ('bye')
###


So pexpect looks like something that might help you with your program.

I hope this helps!