我在 paramiko python 模块“find”和“scp”中使用了两个命令。Find 命令工作正常并给出正确的输出,但 scp 没有给出任何输出。我尝试使用以下代码:
import paramiko
class SSH:
def ssh_Connection(self):
try:
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect('host_name',username='user',password='pass')
except Exception, e:
print "================================================"
print 'ERROR: Remote connection failed with %s' % e
print "================================================"
def ssh_Commands(self):
try:
stdin, stdout, stderr = self.ssh.exec_command('find /result/main/ -name "*new.txt*"')
for line in stdout:
a = line.strip('\n')
print a
if a:
cmd = 'scp -r %s redhat@192.168.56.32:/results/main/' % a
print cmd
stdin, stdout, stderr = self.ssh.exec_command(cmd)
print stdout.read()
print stderr.read()
self.ssh.close()
except Exception, e:
print "================================================"
print 'ERROR: Commands Execution failed with %s' % e
print "================================================"
if __name__ == "__main__":
a = SSH()
a.ssh_Connection()
a.ssh_Commands()
但是这个程序对我不起作用..
Throwing an error:
Host key verification failed.
lost connection
如何在 paramiko 中使用 scp ......任何想法?