gpt4 book ai didi

python-3.x - paramiko 在自己加载 20 MB 的文件后挂起

转载 作者:行者123 更新时间:2023-12-03 23:04:52 25 4
gpt4 key购买 nike

我需要 python sftp 客户端从 sftp 服务器下载文件。我开始使用Paramiko。 KB 中的小文件运行良好,但是当我尝试下载 600 MB 的文件时,它在下载 20 MB 的文件后无限期挂起。无法弄清楚是什么问题。增加窗口大小也没有解决。任何帮助将非常感激!

host = config.getsafe(section, "host")
username = config.getsafe(section, "username")
port = config.getsafe(section, "port")
remote_dir = config.getsafe(section, "remote_dir")
download_dir = config.getsafe(section, "download_dir")
archive_dir = config.getsafe(section, "archive_dir") if config.has_option(section, "archive_dir") else \
None
password = config.getsafe(section, "password") if config.has_option(section, "password") else None
file_pattern = config.getsafe(section, "file_pattern") if config.has_option(section, "file_pattern") \
else "*"
passphrase = config.getsafe(section, "passphrase") if config.has_option(section, "passphrase") else None
gnupg_home = config.getsafe(section, "gnupg_home") if config.has_option(section, "gnupg_home") else None

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, port=int(port), username=username, password=password)

sftp = ssh.open_sftp()
sftp.sshclient = ssh

sftp.get("/SFTP/PL_DEV/test.dat", "C:/import/download/test.dat")

最佳答案

我做了两件事来解决类似的问题:

  • increase window size ——你说你也试过了;对我来说,这有助于从几十 ​​MB 增加到半 GB,但没有进一步
  • effectively disable rekeying – 这可能有安全隐患,但帮助我从一个奇怪的 windows sftp 服务器获取超过 GB 的文件
    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)
  • 关于python-3.x - paramiko 在自己加载 20 MB 的文件后挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45891553/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com