Python Forum
Paramiko SSH "put", destination name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Paramiko SSH "put", destination name
#1
Hello all, I am having difficulties understanding paramiko's behaviour, when it comes to sending files over SSH. I have this function:

def SSH_send_file(file, host, username, password, path):   
   s = paramiko.SSHClient()
   s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
   s.connect(host, 22, username, password)
   sftp = s.open_sftp()
   sftp.put(file, path)
   s.close()
For example, you would call it like:
SSH_send_file("file_to_send.txt", "10.20.30.40", "user", "secret", "/tmp")

Until now, it worked fine using it like in the example above. But now (in same program) there was an occassion when this error happened:
Error:
  File "\lib\site-packages\paramiko\sftp_client.py", line 811, in _convert_status     raise IOError(text) OSError: Failure
After some Googling I found that solution is to pass complete destination name to function, which means the file name included, like this:
SSH_send_file("file_to_send.txt", "10.20.30.40", "user", "secret", "/tmp/file_to_send.txt")

Why did this function "change behaviour", so I had to use it differently in one case, as opposed to previous uses? Can I avoid/predict it in future?
Thank you! JC
Reply
#2
well, no experience with paramiko, but only by reading the docs, I would say always include the filename to avoid errors:

Quote:remotepath (str) – the destination path on the SFTP server. Note that the filename should be included. Only specifying a directory may result in an error.

I would say you were just lucky not getting error on previous occasion
Reply
#3
Alright, behaviour I noticed reflects your quote from the docs. Perhaps I was only lucky so far to not have this error appear. Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python move specific files from source to destination including duplicates mg24 3 1,103 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  Shutil move if file exists in destination Friend 2 6,775 Feb-02-2020, 01:45 PM
Last Post: Friend
  How to specify the destination folder SriMekala 1 3,226 May-21-2019, 11:45 AM
Last Post: DeaD_EyE
  get destination path from item from QlistWidget faithcure 3 3,286 Jul-25-2018, 09:37 PM
Last Post: nilamo
  copy files from one destination to another by reading filename from csv Prince_Bhatia 3 7,648 Feb-27-2018, 10:56 AM
Last Post: Prince_Bhatia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020