Home > Article > Backend Development > python scp自动登录解决方法
python scp自动登录
用pexpect模块 实现scp自动登录功能
代码如下:
#!/usr/bin/env python<br /><br />import os<br />import sys<br />import pexpect<br /><br />cmd = 'scp [email 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()