我正在尝试做SCP并从远程服务器复制一些文件。由于我没有root权限,因此当我提示输入密码时,我会使用sudo命令我使用pexpect发送它,但我无法做到。我被某个地方击中了。
这是我的代码:
import pexpect
def doScp(user,password,host,remotepath,localpath,files):
print files
child = pexpect.spawn('sudo scp -C %s:%s%s %s' % (host, remotepath, files, localpath))
print 'scp -C %s:%s%s %s' % (host, remotepath, files, localpath)
i = child.expect(['assword:', r"yes/no"], timeout=30)
if i == 0:
child.sendline(password)
elif i == 1:
child.sendline("yes")
child.expect("assword:", timeout=30)
child.sendline(password)
data = child.read()
print data
child.close()
user = "xxxxx"
host = "yyyy"
password = "zzzzzz"
remotepath = "/opt/logs/"
localpath = "/opt/Performance_Logs/SRNG/"
files = "receiver.log"
doScp(user,password,host,remotepath,localpath,files)
我得到的错误:
文件“/usr/lib/python2.6/site-packages/pexpect.py”,第1325行,在expect_list中返回self.expect_loop(searcher_re(pattern_list),timeout,searchwindowsize)文件“/usr/lib/python2.6/ site-packages / pexpect.py“,第1409行,在expect_loop中提高TIMEOUT(str(e)+'\ n'+ str(self))
文件“/usr/lib/python2.6/site-packages/pexpect.py”,第1325行,在expect_list中返回self.expect_loop(searcher_re(pattern_list),timeout,searchwindowsize)文件“/usr/lib/python2.6/ site-packages / pexpect.py“,第1409行,在expect_loop中提高TIMEOUT(str(e)+'\ n'+ str(self))
—
Rajesh 2015年