使用Paramiko获取大文件时获取EOFError

时间:2015-02-10 23:04:17

标签: python sftp paramiko pysftp

我正在尝试编写一个快速的python脚本来获取一些带有sftp的日志。我的第一个倾向是使用Pysftp,因为它看起来很简单。它工作得很好,直到它有一个更大的文件。我得到一个错误,同时获得大约13 MB的任何文件。然后我决定尝试直接在Paramiko中编写我需要的内容,而不是依赖于额外的Pysftp层。在弄清楚如何做到这一点后,我最终得到了完全相同的错误。这是Paramiko代码,以及我得到的错误的痕迹。有没有人知道为什么这会有拉动任何大文件的问题?感谢。

# Create tranport and connect
transport = paramiko.Transport((host, 22))
transport.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(transport)

# List of the log files in c:
files = sftp.listdir('c:/logs')
# Now pull them, logging as you go
for f in files:
    if f[0].lower() == 't' or f[:3].lower() == 'std':
      logger.info('Pulling {0}'.format(f))
      sftp.get('c:/logs/{0}'.format(f), output_dir +'/{0}'.format(f))

# Close the connection
sftp.close()
transport.close()

这是错误:

No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
  File "pull_logs.py", line 420, in <module> main()
  File "pull_logs.py", line 410, in main
    pull_logs(username, host, password, location)
  File "pull_logs.py", line 142, in pull_logs
    sftp.get('c:/logs/{0}'.format(f), output_dir +'/{0}'.format(f))
  File "/Users/me/my_site/site_packages/paramiko/sftp_client.py", line 676, in get
    size = self.getfo(remotepath, fl, callback)
  File "/Users/me/my_site/site_packages/paramiko/sftp_client.py", line 645, in getfo
    data = fr.read(32768)
  File "/Users/me/my_site/site_packages/paramiko/file.py", line 153, in read
    new_data = self._read(read_size)
  File "/Users/me/my_site/site_packages/paramiko/sftp_file.py", line 152, in _read
    data = self._read_prefetch(size)
  File "/Users/me/my_site/site_packages/paramiko/sftp_file.py", line 132, in _read_prefetch
    self.sftp._read_response()
  File "/Users/me/my_site/site_packages/paramiko/sftp_client.py", line 721, in _read_response
    raise SSHException('Server connection dropped: %s' % (str(e),))
paramiko.SSHException: Server connection dropped: 

0 个答案:

没有答案