我在paramiko python模块“find”和“scp”中使用了两个命令。 查找命令工作正常,并给出正确的输出,但scp没有给出任何输出。 我试着用下面的代码:如何在paramiko中使用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 [email protected]:/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 ...任何想法?
我用'scp -o UserKnownHostsFile =/dev/null -o StrictHostKeyChecking = no -r%s [email protected]替换了'scp -r%s [email protected]:/ results/main /'%a。 56.32:/ results/main /'%a它没有显示任何东西,甚至没有我的find命令输出。 – 2013-03-07 07:18:34
尝试sshing到'host_name'并手动执行该命令以查看它是否工作。 – robertklep 2013-03-07 07:30:26
显示一个警告:将“192.168.56.32”(RSA)永久添加到已知主机列表中。 – 2013-03-07 08:57:06