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.
更多推荐
发布评论