我在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