Python : Using Pexpect: ftpTest.py

#!/usr/bin/python

# Connects to a public ftp server, downloads a file

import pexpect
import sys
child = pexpect.spawn('ftp ftp.ubuntu.com')
child.logfile = sys.stdout
child.expect('Name')
child.sendline('anonymous')
child.expect('Password')
child.sendline('anonymous')
child.expect('ftp>')
child.sendline('cd /ubuntu/dists/xenial')
child.expect('ftp>')
child.sendline('get InRelease')
child.expect('ftp>')
child.sendline('quit')