我正在尝试从带有Paramiko模块的win 7机器中检索ubuntu服务器上的文件

时间:2011-07-14 18:02:21

标签: python windows paramiko

当我使用get方法(Paramiko)设置我的Windows文件系统的本地路径名时,我收到了“权限被拒绝”错误。有没有人遇到这个或知道如何解决它?我以管理员身份登录。下面是代码和回溯错误。谢谢!

代码:

 import paramiko
 import sys
 import os





 ssh = paramiko.SSHClient()
 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 ssh.connect('10.5.48.72', username='root', password='******')


 apath = '/var/log'
 apattern = '"*.log"'
 rawcommand = 'find {path} -name {pattern}'
 command = rawcommand.format(path=apath, pattern=apattern)
 stdin, stdout, stderr = ssh.exec_command(command)
 filelist = stdout.read().splitlines()

这是正确的代码。它在根目录下搜索所有日志和文本文件的Ubuntu服务器,并检索文件并将它们保存到本地目录(c:\ Extracted):

sim_ip = raw_input('Host: ')
pattern = r"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"

if re.match(pattern, sim_ip):

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(sim_ip, username='root', password='*****')
apath = '/'
apattern = '"*.txt" -o -name "*.log"' 
rawcommand = 'find {path} -name "*.txt" -o -name "*.log"' #{pattern}
command = rawcommand.format(path=apath, pattern=apattern)
stdin, stdout, stderr = ssh.exec_command(command)
filelist = stdout.read().splitlines()
ftp = ssh.open_sftp() 
for afile in filelist:
    (head, filename) = os.path.split(afile)
    print(filename)
    ftp.get(afile, 'c:\\Extracted\\' + filename)  #'./'+filename)

ftp.close()
ssh.close()

else:
    print "You entered an invalid IP Address!!!" 

0 个答案:

没有答案