Python paramiko SFTP IOError

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))
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值