paramiko hangs on get after ownloading 20 MB of file

前端 未结 3 1234
孤独总比滥情好
孤独总比滥情好 2021-01-03 05:56

I am in need of python sftp client to download files from a sftp server. I started to use Paramiko. Small files in KB works well but however when I try to download 600 MB of

3条回答
  •  旧时难觅i
    2021-01-03 06:28

    I did two things to solve a similar problem:

    1. increase window size – you say you tried that too; for me, this helped to get from a few ten MBs to half a GB but no further

    2. effectively disable rekeying – this might have security implications, but helped me to get files over a GB from a weird windows sftp server

      with paramiko.Transport((_SFTP['host'], 22)) as transport:
          # SFTP FIXES
          transport.default_window_size=paramiko.common.MAX_WINDOW_SIZE
          transport.packetizer.REKEY_BYTES = pow(2, 40)  # 1TB max, this is a security degradation!
          transport.packetizer.REKEY_PACKETS = pow(2, 40)  # 1TB max, this is a security degradation!
          # / SFTP FIXES
      
          transport.connect(username=_SFTP['user'], password=_SFTP['password'])
              with paramiko.SFTPClient.from_transport(transport) as sftp:
                  listdir = sftp.listdir()
                  # ...
                  sftp.get(remotepath=filename, localpath=localpath)
      

提交回复
热议问题