Python paramiko SFTP IOError

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kwame211/article/details/82013791

4down votefavorite

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

python paramiko

shareimprove this question

asked Jul 25 '15 at 10:25

user3702643

3442717

  • Unreadable file ! Which file's allowed "wb" mode ? – dsgdfg Jul 25 '15 at 10:39

  • Unreadable file means local or on the remote server? Both directories have chmod 777 – user3702643 Jul 25 '15 at 13:36

add a comment

1 Answer

activeoldestvotes

up vote11down voteaccepted

change:

sftp.put(full_fname, remote_path)

to:

sftp.put(full_fname, os.path.join(remote_path, fname))

猜你喜欢

转载自blog.csdn.net/kwame211/article/details/82013791