Download files over SSH using Python

2019-02-17 05:09发布

I am trying to make a script that downloads ( or upload ) files over ssh, as ftp port is disabled from firewall. This is my script :

import os
import paramiko 
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.170.21.93', username="abhishek", password="@bhishek$")
sftp = ssh.open_sftp()
localpath = 'abc.txt'
remotepath = '/opt/crestelsetup/patchzip'
sftp.put(localpath, remotepath)
sftp.close()
ssh.close()

This is giving me "IOError: Failure", can any one help?

标签: python ssh
2条回答
ゆ 、 Hurt°
2楼-- · 2019-02-17 05:21

You need to explicitly specify the remote path:

import os
import paramiko 
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.170.21.93', username="abhishek", password="@bhishek$")
sftp = ssh.open_sftp()
localpath = 'abc.txt'
remotepath = '/opt/crestelsetup/patchzip/abc.txt'
sftp.put(localpath, remotepath)
sftp.close()
 ssh.close()
查看更多
Rolldiameter
3楼-- · 2019-02-17 05:36

Just modified the destination path to include the file name as well.Try to change.

remotepath = '/opt/crestelsetup/patchzip'

to

remotepath = '/opt/crestelsetup/patchzip/abc.txt'
查看更多
登录 后发表回答