python scp自动登录解决方法

WBOY
Release: 2016-06-13 11:52:57
Original
1769 people have browsed it

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()
Copy after login


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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template