I'm fairly new to Python, and finding it to be very powerful thus far.
I have substituted the domain, username, password, and file names to preserve confidentiality.
I am looking to add somewhere in this code to be able to read and/or list the file names and determine if the script should continue to run or not. The parameters would be the date. So have the script run each day and if there's a package for that day, have the script execute a download of that file to my temp directory. Any insight would be appreciated!
Copy and pasting my code below:
I have substituted the domain, username, password, and file names to preserve confidentiality.
I am looking to add somewhere in this code to be able to read and/or list the file names and determine if the script should continue to run or not. The parameters would be the date. So have the script run each day and if there's a package for that day, have the script execute a download of that file to my temp directory. Any insight would be appreciated!
Copy and pasting my code below:
import os import ftplib # log in to FTP Site ftp = ftplib.FTP("domain.com") ftp.login("username", "password") # Change directory ftp.cwd("Directory") # set up file name structure fnbase = "Package_" fnmid = "Version1.0_" fnend = "year_month_day.zip" # Select a location to save file download savedir = "C:/temp" os.chdir(savedir) # Execute download fn = fnbase + fnmid + fnend file = open(fn, "wb") ftp.retrbinary("RETR " + fn, file.write) file.close() print("Done")