Calling ftp commands from python

Cameron Laird claird at lairds.us
Wed Aug 31 20:08:06 EDT 2005


In article <1125521945.668330.24190 at g47g2000cwa.googlegroups.com>,
draghuram at gmail.com <draghuram at gmail.com> wrote:
>
>Your best bet would be to use "pexpect" module. Code may look something
>like:
>
>import pexpect
>import sys
>child = pexpect.spawn ('ftp ftp.site.com')
>child.expect ('Name .*: ')
>child.sendline ('username')
>child.expect ('Password:')
>child.sendline ('password')
>child.expect ('ftp> ')
>child.sendline ('cd testdir')
>child.expect ('ftp> ')
>child.sendline ('bin')
>child.expect ('ftp> ')
>child.sendline ('hash')
>child.expect ('ftp> ')
>child.sendline ('get  testfile')
>child.expect ('ftp> ')
>print child.before  
>child.sendline ('bye')
>
>Raghu.
>~
>

... and, for those for whome pexpect is somehow infeasible,
there are a variety of ways to work around its absence <URL:
http://phaseit.net/claird/comp.unix.programmer/ftp_automation.html >.



More information about the Python-list mailing list