Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File to Download Latest Files by Date  (Read 3671 times)

0 Members and 1 Guest are viewing this topic.

rmoss25

  • Guest
Batch File to Download Latest Files by Date
« on: July 28, 2009, 06:08:29 AM »
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


gpl



    Apprentice
  • Thanked: 27
    Re: Batch File to Download Latest Files by Date
    « Reply #1 on: July 28, 2009, 11:27:09 AM »
    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

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Batch File to Download Latest Files by Date
      « Reply #2 on: July 28, 2009, 01:53:21 PM »
      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="[email protected]"
      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