paramiko 在自己加载 20 MB 的文件后挂起 [英] paramiko hangs on get after ownloading 20 MB of file
问题描述
我需要 python sftp 客户端来从 sftp 服务器下载文件.我开始使用Paramiko.KB 中的小文件运行良好,但是当我尝试下载 600 MB 的文件时,它在下载 20 MB 的文件后无限期挂起.无法弄清楚是什么问题.增加窗口大小也没有解决.任何帮助将不胜感激!
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 file, it hangs indefinitely after downloading 20 MB of file. Unable to figure out what the issue is. Increasing the window size did not solve either. Any help would be much appreciated!
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")
推荐答案
我做了两件事来解决类似的问题:
I did two things to solve a similar problem:
增加窗口大小 – 你说你也试过了;对我来说,这有助于从几十 MB 增加到半 GB,但没有进一步
有效禁用重新加密 - 这可能具有安全性影响,但帮助我从一个奇怪的 Windows sftp 服务器获取超过 GB 的文件
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)
这篇关于paramiko 在自己加载 20 MB 的文件后挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!