How to download a file via FTP with Python ftplib

后端 未结 7 1770
名媛妹妹
名媛妹妹 2020-12-05 12:51

I have the following code which easily connects to the FTP server and opens a zip file. I want to download that file into the local system. How to do that?

#         


        
7条回答
  •  醉梦人生
    2020-12-05 13:01

    FILENAME = 'StarWars.avi'    
    
    with ftplib.FTP(FTP_IP, FTP_LOGIN, FTP_PASSWD) as ftp:
        ftp.cwd('movies')
        with open(FILENAME, 'wb') as f:
            ftp.retrbinary('RETR ' + FILENAME, f.write)
    

    Of course it would we be wise to handle possible errors.

提交回复
热议问题