Upload files via SSH using Python

I am trying to create a script that uploads (or uploads) files via ssh since the ftp port is disconnected from the 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 gives me "IOError: Failure", can anyone help?

+6
source share
2 answers

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() 
+4
source

Just changed the destination path to include the file name. Try to change.

 remotepath = '/opt/crestelsetup/patchzip' 

before

 remotepath = '/opt/crestelsetup/patchzip/abc.txt' 
+1
source

Source: https://habr.com/ru/post/984835/


All Articles