1

我正在尝试编写一个快速的 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: 
4

0 回答 0