3 """This demonstrates an FTP "bookmark". This connects to an ftp site; does a
4 few ftp stuff; and then gives the user interactive control over the session. In
5 this case the "bookmark" is to a directory on the OpenBSD ftp server. It puts
6 you in the i386 packages directory. You can easily modify this for other sites.
12 child = pexpect.spawn('ftp ftp.openbsd.org')
13 child.expect('(?i)name .*: ')
14 child.sendline('anonymous')
15 child.expect('(?i)password')
18 child.sendline('cd /pub/OpenBSD/3.7/packages/i386')
22 child.sendline('prompt')
26 print("Escape character is '^]'.\n")
27 sys.stdout.write (child.after)
29 child.interact() # Escape character defaults to ^]
30 # At this point this script blocks until the user presses the escape character
31 # or until the child exits. The human user and the child should be talking
34 # At this point the script is running again.
35 print 'Left interactve mode.'
37 # The rest is not strictly necessary. This just demonstrates a few functions.
38 # This makes sure the child is dead; although it would be killed when Python exits.
40 child.sendline('bye') # Try to ask ftp child to exit.
42 # Print the final state of the child. Normally isalive() should be FALSE.
44 print 'Child did not exit gracefully.'
46 print 'Child exited gracefully.'