Paramiko sftp put request getting terminated with EOFError() in python

僤鯓⒐⒋嵵緔 提交于 2019-12-06 15:23:12

问题


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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/50588450/paramiko-sftp-put-request-getting-terminated-with-eoferror-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!