How to download a file via FTP with Python ftplib

后端 未结 7 1774
名媛妹妹
名媛妹妹 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:02

    A = filename
    
    ftp = ftplib.FTP("IP")
    ftp.login("USR Name", "Pass")
    ftp.cwd("/Dir")
    
    
    try:
        ftp.retrbinary("RETR " + filename ,open(A, 'wb').write)
    except:
        print "Error"
    

提交回复
热议问题