Home  >  Article  >  Backend Development  >  python scp自动登录解决方法

python scp自动登录解决方法

WBOY
WBOYOriginal
2016-06-13 11:52:571770browse

python scp自动登录
用pexpect模块 实现scp自动登录功能
代码如下:

#!/usr/bin/env python<br /><br />import os<br />import sys<br />import pexpect<br /><br />cmd = 'scp [email&#160;protected]:/usr/local/files /usr/local/'<br />print cmd<br />child = pexpect.spawn(cmd)<br />child.expect('.ssword:')<br />child.sendline(passwd)<br />child.interact()


添加child.interact()会告警,如下

不添加不能自动填写密码,我用的Python2.6

想问下 警告怎样消除呢?是缓存区需要刷新么?谢谢大家
------解决方案--------------------
用shell来实现吧,调用expect工具

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn