Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'put' in SFTP using Paramiko

I've installed and written the following Paramiko which is unable to put the file. It is easily able to 'get' a file and execute ls commands on it.

#set username & password username='runaway' password='runaway' port=22 source= '/Unzip.sh'  destination ='/var/mpx/www/http'   #SFTP client.load_system_host_keys() print " hostname =%s \n username=%s \n password=%s \n" (hostname,username,password) t = paramiko.Transport((hostname, port))  t.connect(username=username,password=password) sftp = paramiko.SFTPClient.from_transport(t) sftp.put(source,destination) #sftp.close() #t.close() 

Using a 'put' command gives the following error & stack trace -

File "upload_file.py", line 84, in ?     sftp.put(source,destination)   File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 522, in put     fr = self.file(remotepath, 'wb')   File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 221, in open     t, msg = self._request(CMD_OPEN, filename, imode, attrblock)   File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 572, in _request     return self._read_response(num)   File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 619, in _read_response     self._convert_status(msg)   File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 649, in _convert_status     raise IOError(text) IOError: Failure 

How do I overcome this?

like image 287
fixxxer Avatar asked Jun 22 '10 08:06

fixxxer


People also ask

How connect paramiko to SFTP?

from paramiko import Transport, SFTPClient, RSAKey key = RSAKey(filename='path_to_my_rsakey') con = Transport('remote_host_name_or_ip', 22) con. connect(None,username='my_username', pkey=key) sftp = SFTPClient. from_transport(con) sftp. listdir(path='.

How do I transfer files using SFTP in Python?

To run the file transferring program over a secure shell, you need to use the pysftp module in your Python program. This module is wrapped around paramiko and utilizes pycrypto libraries to perform the secure transferring of data. Pysftp is easy to implement.

How do I use paramiko in Python?

A Paramiko SSH Example: Connect to Your Server Using a Password. This section shows you how to authenticate to a remote server with a username and password. To begin, create a new file named first_experiment.py and add the contents of the example file. Ensure that you update the file with your own Linode's details.

What is paramiko transport?

class paramiko.Transport. An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, authenticates, and then creates stream tunnels, called Channels, across the session. class paramiko.SSHClient. A high-level representation of a session with an SSH server.


1 Answers

The solution seemed very funny to me!

source= '/Unzip.sh'  destination ='/var/mpx/www/http/Unzip.sh' 

Just modified the destination path to include the file name as well. Didn't expect some error like this coming from a Python package.

like image 85
fixxxer Avatar answered Sep 23 '22 09:09

fixxxer