I am writing a Python script that needs to download a remote XML file to parse it.
I use paramiko for this.
Here is the script:
def copyFile(ip, user, pwd, remotePath, localPath):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip,username=user,password=pwd)
sftp = ssh.open_sftp()
sftp.get(remotePath,localPath)
sftp.close()
ssh.close()
return ["OK",0,0]
except IOError as e:
flash(str(e)+" IOERROR")
return ["IOERROR: " + str(e),0,0]
except Exception as e:
flash(str(e)+" OTHER EXCEPTION")
return ["Error: " + str(e),0,0]
The code returns and an IOError says the file does not exist.
But if I change the variable for strings, it works fine .:
`sftp.get("/etc/conf/file-cfg.xml","./conf/file-cfg.xml")`
Variables are passed correctly:
`copyFile(ip,username,pwd,"/etc/conf/"+i,"."+i)`
I lost a lot of time trying to figure out what was wrong with success.
My remote computer: Ubuntu 13.10 x64 Local computer: Windows 7 x64
source
share