Python:ftp文件卡在缓冲区?(Python: ftp file stuck in buffer?)

编程入门 行业动态 更新时间:2024-10-28 19:19:03
Python:ftp文件卡在缓冲区?(Python: ftp file stuck in buffer?)

当我使用此方法使用ftplib下载文件时:

ftp = ftplib.FTP() ftp.connect("host", "port") ftp.login("user", "pwd") size = ftp.size('locked') def handleDownload(block): f.write(block) pbar.update(pbar.currval+len(block)) f = open("locked", "wb") pbar=ProgressBar(widgets=[FileTransferSpeed(), Bar('>'), ' ', ETA(), ' ', ReverseBar('<'), Percentage()], maxval=size).start() ftp.retrbinary("RETR locked",handleDownload, 1024) pbar.finish()

如果文件小于1mb,文件将卡在缓冲区中,直到我下载另一个有足够数据的文件将其推出。 我试图通过将ftp.size(filename)除以20来制作动态缓冲区,但仍然会发生同样的事情。 那么如何制作它以便我可以下载小于1 mb的单个文件并仍然使用回调函数?

When I download a file with ftplib using this method:

ftp = ftplib.FTP() ftp.connect("host", "port") ftp.login("user", "pwd") size = ftp.size('locked') def handleDownload(block): f.write(block) pbar.update(pbar.currval+len(block)) f = open("locked", "wb") pbar=ProgressBar(widgets=[FileTransferSpeed(), Bar('>'), ' ', ETA(), ' ', ReverseBar('<'), Percentage()], maxval=size).start() ftp.retrbinary("RETR locked",handleDownload, 1024) pbar.finish()

if the file is less than 1mb the file will be stuck in the buffer until I download another file with enough data to push it out. I have tried to make a dynamic buffer by dividing the ftp.size(filename) by 20 but the same thing still happens. So how do I make it so I can download single files less than 1 mb and still use the callback function?

最满意答案

正如Wooble在评论中所说的那样,我并没有把这个文件像个白痴一样关闭。 它解决了这个问题。

As Wooble stated in comments I did not f.close() the file like an idiot. It fixed the problem.

更多推荐

本文发布于:2023-08-06 02:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓冲区   卡在   文件   ftp   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!