|
Answer» Hi all, I am trying to write a batch file that will login to symantecs's FTP site and download the latest virus files based on date. So far I am able to login to the FTP site, download the contents for the directory and then push only the files (without the DIRECTORIES) to another file. The problem is how to I grab the latest date and then download FROMT the FTP server based on the latest date? PERHAPS their is an easier WAY to do this withoud downloading the directory list to a file. Here is what I have so far
ftp -s:login symantec.com
**login File*** anonymous anonymous dir AVDEFS/symantec_antivirus_corp TLIST
After the TLIST file is downloaded to the local PC I run the following Batch File to remove directories
findstr /b /v "d" TLIST > svrlist
Is their a way to make this easier and just download the files from the FTP directory based on the date
No, you have it pretty much right, there are few things that you can do within an FTP session, so downloading the directory list is the way to go.
I dont know the contents of the site, are the filenames datestamped ? if so then SORTING the TLIST file would be useful, if you make the newest file at the top, then the following will retrieve the name :
Code: [Select]:: put newest file into %Latest% Set Latest=<TLIST.SRT you can use Python, or even Perl's FTP module for better control of your ftp session. If you can have such "luxury", here's a working Python script
Code: [Select]import ftplib server="ftp.symantec.com" user="anonymous" password="[emailprotected]" filelist=[] v=[] def download(ftp, filename): ftp.retrbinary("RETR " + filename, open(filename,"wb").write) try: ftp = ftplib.FTP() #ftp.debug(3) ftp.connect(server,21) ftp.login(user,password) except Exception,e: print e else: ftp.cwd("AVDEFS/symantec_antivirus_corp") ftp.retrlines('LIST',filelist.append) for i in filelist: if i.startswith("-") and "exe" in i: virusdat = i.split()[-1] if virusdat[0].isdigit(): v.append(virusdat) latest = sorted(v)[-1] download(ftp,latest) ftp.quit()
on the command line Code: [Select]c:\test> python myscript.py
|