pexpect02-之ftp

来源:互联网 发布:java语言发展历史 编辑:程序博客网 时间:2024/06/13 19:05
from __future__ import unicode_literalsimport pexpectimport syschild = pexpect.spawn('ftp ftp.sjtu.edu.cn')child.expect('(?i)root')child.sendline('anonymous')child.expect('(?i)password')child.sendline('anonymous')child.expect('ftp> ')child.sendline('bin')child.expect('ftp> ')child.sendline('cd /centos/7.3.1611/cloud/x86_64/openstack-ocata/')child.expect('ftp> ')child.sendline('get openstack-aodh-api-4.0.0-1.el7.noarch.rpm')child.expect('ftp> ')sys.stdout.write(child.before)print ("Escape character is '^]'.\n")sys.stdout.write(child.after)sys.stdout.flush()child.interact()child.sendline('bye')child.close()

centos镜像的一个下载的ftp网站:
这里写图片描述

测试连通性(ip地址为 202.38.97.230)
这里写图片描述

这里写图片描述

参考:python自动化开发运维