I was working in a pexpect script in order to establish a ftp connection, I followed the following approach:
#!/usr/bin/python
import pexpect
child = pexpect.spawn ('ftp mydomanin.com.mx')
child.expect ('.*[Nn]ame.*: ')
child.sendline ('user')
child.expect ('Password:')
child.sendline ('mypassword')
child.interact()
This works well the connection is establish, but the problem comes when I add the following line to the script
child.expect ('ftp> ', )
The script doesn't do nothing if I add this line, I don't know what is the reason for this i would appreciate any help whit this issue.
If you are calling child.interact()
then you need not call child.expect()
afterwards. (Assuming you are calling it afterwards).
You are expecting ftp prompt ftp>
from your script. It will automatically appear after the interact call. If you are calling child.expect('ftp>')
before the call to interact then hitting return will get the desired prompt. Expecting 'ftp>' is obsolete in this case however.