[root@server0 318]# cat ftp.py 
#!/usr/bin/python
import pexpect
import sys
ip="172.25.254.2"
user="root"
password="redhat"
try:
	child=pexpect.spawn('/usr/bin/ssh',[user+'@'+ip])
	target_file="/root/Django-1.7.11"
	four=file('mylog.txt','w')
	child.logfile=four		输入输出写道文件里面
	child.expect('(?i)password')		(?i)表示不区别大小写
	child.sendline(password)
	child.expect('#')
	child.sendline('tar -czf /mnt/mimi.tar.gz '+target_file)
	child.expect('#')
	print child.before
	child.sendline('exit')
	four.close()
except:
	print "failed"
child1=pexpect.spawn('/usr/bin/scp',[user+'@'+ip+':/mnt/mimi.tar.gz','/mnt/'])
four1=file('loffile.txt','w')
child1.logfile=four1
child1.expect('(?i)password')
child1.sendline(password)
child1.expect(pexpect.EOF)	匹配缓冲区EOF(结尾),保证文件复制正常完成

远程文件自动打包并下载

相关文章:

  • 2021-10-29
  • 2021-10-19
  • 2021-11-22
  • 2021-11-27
  • 2021-12-23
  • 2021-08-07
  • 2021-12-08
  • 2022-01-02
猜你喜欢
  • 2021-11-06
  • 2021-11-12
  • 2021-10-17
  • 2021-11-04
  • 2021-10-18
  • 2021-07-16
  • 2021-03-29
  • 2021-12-25
相关资源
相似解决方案