Python Forum

Full Version: SFTP transfer using paramiko fails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Amigos,

I need to automate a file transfer via SFTP to several devices and i have found thousands of code using paramiko i am not very experienced with python and i took the code below but is not working i have done a lot of debugs and it seems a problem with paths but i have tried a lot of things and couldnt solve it, appreciate your kind help with any recommendation.

Details: Code error execution as follows:

PS C:\00Python> python .\ Traceback (most recent call last): File ".\", line 9, in <module> sftp.put('','/') File "C:\Python27\lib\site-packages\paramiko\", line 727, in put return self.putfo(fl, remotepath, file_size, callback, confirm) File "C:\Python27\lib\site-packages\paramiko\", line 683, in putfo with self.file(remotepath, 'wb') as fr: File "C:\Python27\lib\site-packages\paramiko\", line 341, in open t, msg = self._request(CMD_OPEN, filename, imode, attrblock) File "C:\Python27\lib\site-packages\paramiko\", line 780, in _request return self._read_response(num) File "C:\Python27\lib\site-packages\paramiko\", line 832, in _read_response self._convert_status(msg) File "C:\Python27\lib\site-packages\paramiko\", line 865, in _convert_status raise IOError(text) IOError
TSHOOT: I´ve checked paramiko generated log and i can see the following error:

DEB [20180906-11:57:27.368] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group-exchange-sha1
DEB [20180906-11:57:27.368] thr=1 paramiko.transport: HostKey agreed: ssh-rsa
DEB [20180906-11:57:27.368] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20180906-11:57:27.368] thr=1 paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20180906-11:57:27.368] thr=1 paramiko.transport: Compression agreed: none
DEB [20180906-11:57:27.539] thr=1 paramiko.transport: Got server p (2048 bits)
DEB [20180906-11:57:28.223] thr=1 paramiko.transport: kex engine KexGex specified hash_algo <built-in function openssl_sha1>
DEB [20180906-11:57:28.223] thr=1 paramiko.transport: Switch to new keys ...
DEB [20180906-11:57:28.255] thr=2 paramiko.transport: Attempting password auth...
DEB [20180906-11:57:28.499] thr=1 paramiko.transport: userauth is OK
INF [20180906-11:57:29.130] thr=1 paramiko.transport: Authentication (password) successful!
DEB [20180906-11:57:29.154] thr=2 paramiko.transport: [chan 0] Max packet in: 32768 bytes
DEB [20180906-11:57:29.332] thr=1 paramiko.transport: [chan 0] Max packet out: 32768 bytes
DEB [20180906-11:57:29.334] thr=1 paramiko.transport: Secsh channel 0 opened.
DEB [20180906-11:57:29.403] thr=1 paramiko.transport: [chan 0] Sesch channel 0 request ok
INF [20180906-11:57:29.549] thr=2 paramiko.transport.sftp: [chan 0] Opened sftp connection (server version 3)
DEB [20180906-11:57:29.555] thr=2 paramiko.transport.sftp: [chan 0] open('sd1:/', 'wb')
DEB [20180906-11:57:29.838] thr=1 paramiko.transport: EOF in transport thread

System info: Windows 10 64 bit Python 2.7.15


import paramiko
import subprocess
ssh_client = paramiko.SSHClient()
ssh_client.connect('', 22, 'python', 'python')
sftp = ssh_client.open_sftp()