Python: How to download file using FTP?

Download the following script from Here.

####
#Download File with FTP.
#Download_System requires two variables HOST & directory & filename
####

import ftplib
import sys

#Host and Gets the Filename of the Preset
def Download_System(HOST,directory,filename):
  try:
    filename_get=filename
    directory_get=directory
    ftp_download=ftplib.FTP(HOST) #opens Ftp Connection to the HOST
    ftp_download.login( "root", "root") #username, password
    ftp_download.cwd(directory_get) #Change Directory to file directory
    localfile=open(filename_get,'wb') #Open Localfile to write
    ftp_download.retrbinary("RETR " + filename_get, localfile.write) #Get the Filname in Binary
  except Exception as e:
    print ":::ERROR:::: " +str(e)

if __name__=="__main__":
  HOST='Host'
  Filename='Filename'
  Directory='Change Directory Here'
  Download_System(HOST,Directory,Filename)

Leave a Reply

Your email address will not be published. Required fields are marked *