Paramiko sftp put请求在python中被EOFError()终止 [英] Paramiko sftp put request getting terminated with EOFError() in python

查看:873
本文介绍了Paramiko sftp put请求在python中被EOFError()终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python的sftp模块"Paramiko"上传几个大小在20至30 MB之间的.zip文件.我能够成功连接到sftp服务器,也能够列出目标目录中的内容.但是,当尝试从我的ec2 linux计算机上载文件时,请求占用了太多时间,然后以EOFError()终止.下面是代码,

I'm trying to upload couple of .zip files with size ranging between 20 to 30 MBs using python's sftp module 'Paramiko'. I'm able to successfully connect to the sftp server, and also able to list the contents in the destination directory. But while attempting to upload files from my ec2 linux machine, the request is taking too much time and then terminating with EOFError(). Below is the code,

>>> import paramiko
>>> import os
>>> ftp_host='*****'
>>> ftp_username='***'
>>> ftp_password='**'
>>> ssh_client=paramiko.SSHClient()
>>> ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh_client.connect(hostname=ftp_host,username=ftp_username,password=ftp_password, timeout=500)
>>> ftp_client=ssh_client.open_sftp()
>>> ftp_client.chdir('/inbound/')
>>> ftp_client.listdir()
[u't5-file-1.zip', u'edp_r.zip', u'T5_Transaction_Sample.gz']
>>> ftp_client.put("/path-to-zip-files-on-local/edp_revenue.zip","/inbound/edp_revenue.zip")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 669, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 626, in putfo
    fr.write(data)
  File "/usr/lib/python2.7/dist-packages/paramiko/file.py", line 331, in write
    self._write_all(data)
  File "/usr/lib/python2.7/dist-packages/paramiko/file.py", line 448, in _write_all
    count = self._write(data)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_file.py", line 176, in _write
    self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), data[:chunk]))
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 750, in _async_request
    self._send_packet(t, msg)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp.py", line 170, in _send_packet
    self._write_all(out)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp.py", line 135, in _write_all
    raise EOFError()
EOFError

当我使用curl命令尝试相同的操作时,我很容易就能做到,而且只需20秒.我在这里想念什么?是造成请求超时的大小还是其他任何原因.

When I'm trying the same thing using curl command I'm easily able to do and just in 20 seconds. What am I missing here? Is it the size which is making the request to timed out or anything else.

推荐答案

似乎我在Linux服务器上使用的是paramiko的较旧版本.我使用升级了

It seems I was using an older version of paramiko on my linux server. I upgraded it using,

 pip install --upgraded paramiko

,然后将所有内容记录在日志文件中,

and then logged everything in a log file,

paramiko.util.log_to_file('/path_to_log_file/paramiko.log')

只是为了捕捉每个细节.现在,它似乎正在快速而正确地工作.

just to capture every detail. Now it seems to be working pretty fast and correct.

这篇关于Paramiko sftp put请求在python中被EOFError()终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆