Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python paramiko SFTP IOError

I am trying to create a python script that connects to my server and sends some files over via SFTP. But the problem is I keep getting

IOError: Failure

Does anyone know why this is happening? The directory on my local PC has multiple files.

Code:

import paramiko
import os

local_path = "/home/user/Desktop/test"
remote_path = "/home/user/files/html/"

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('ipaddress', username="user", password="user")

sftp = ssh.open_sftp()
for root, dirs, files in os.walk(local_path):
    for fname in files:
        full_fname = os.path.join(root, fname)
        sftp.put(full_fname, remote_path)

sftp.close()
ssh.close()

Traceback:

Traceback (most recent call last):
  File "ftp_test.py", line 16, in <module>
    sftp.put(full_fname, remote_path)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 669, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 621, in putfo
    with self.file(remotepath, 'wb') as fr:
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 327, in open
    t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 729, in _request
    return self._read_response(num)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 776, in _read_response
    self._convert_status(msg)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 806, in _convert_status
    raise IOError(text)
IOError: Failure
like image 999
user3702643 Avatar asked Nov 30 '22 00:11

user3702643


1 Answers

change:

sftp.put(full_fname, remote_path)

to:

sftp.put(full_fname, os.path.join(remote_path, fname))
like image 125
Student Jack Avatar answered Dec 05 '22 13:12

Student Jack