I want to use ftplib to download a file.
import ftplib
class Ftp:
def start(self):
self.ftp = ftplib.FTP('speedtest.tele2.net')
self.ftp.login()
with open('1GB.zip', 'wb') as f:
result = self.ftp.retrbinary('RETR 1GB.zip', f.write)
def stop(self):
self.ftp.sock.close()
My first question is, when I call start()
, I can see there is a file in File Explorer which its size is keep growing up. However, nothing on the screen. How can I call print('#', end='')
while downloading? Like the following pic.
Second. When I call stop()
, there is nothing happened because the file size is keep growing up. I've also try self.ftp.abort()
but it will hang the whole process. How can I stop the downloading process at any time?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…