0

I'm setting PC with McAfee install on them and be told that I need to stop the program going on line to download update (DAT). I need to create a script to download dat file from McAfee web site and put this file on server where McAfee can access and install this.

Has anyone done this in past.

Lalajee
  • 139
  • 1
  • 9

1 Answers1

1

I actually have done this. I haven't tested this script in a year or two but here is what I was using. This isn't written in Powershell but if you change the directories I think this can run on Windows.

#!/usr/bin/python

import ftplib
import tarfile
import shutil
import os
import re
import time

scannerDir = "/usr/local/uvscan/"
tmp = "/tmp/avscanner/"

def downloadDat():
    datfile = ""
    r = re.compile("^avvdat")
    ftp = ftplib.FTP("ftp.nai.com", "anonymous", "email@yourdomain.com")
    ftp.cwd("/pub/datfiles/english")
    list = ftp.nlst()
    for x in list:
        if r.search(x):
            datFile = x
    f = open(tmp + "datfile", 'wb')
    ftp.retrbinary("RETR " + datFile, f.write)
    f.close()
    ftp.quit()

def unpackDat():
    tFile = tarfile.open(tmp + "datfile", 'r')
    for f in tFile.getnames():
        tFile.extract(f, tmp)

def createDirs():
    if os.path.isdir(tmp) == False:
        os.mkdir(tmp, 0700)
    os.chown(tmp, 0, 95)
    os.chmod(tmp, 0755)

def doCleanup():
    shutil.rmtree(tmp)

def installFiles():
    shutil.copyfile(tmp + "/avvclean.dat", scannerDir + "/avvclean.dat")
    shutil.copyfile(tmp + "/avvnames.dat", scannerDir + "/avvnames.dat")
    shutil.copyfile(tmp + "/avvscan.dat", scannerDir + "/avvscan.dat")          

def isOld():
    if os.path.isfile(scannerDir + "/avvclean.dat"):
        if time.time() - os.path.getctime(scannerDir + "/avvclean.dat") < 80000:
            return True
        else:
            return False
    else:
        return True

def main():
    if isOld():
        createDirs()
        downloadDat()
        unpackDat()
        installFiles()  
        doCleanup()

if __name__ == "__main__":
    main()
jdabney
  • 126
  • 3
  • I keep getting these erros. Traceback (most recent call last): File "D:\Script\mcAfee Script2.py", line 64, in main() File "D:\Script\mcAfee Script2.py", line 57, in main createDirs() File "D:\Script\mcAfee Script2.py", line 35, in createDirs os.chown(tmp, 0, 95) AttributeError: 'module' object has no attribute 'chown' – Lalajee Apr 03 '12 at 10:04
  • This script used to run on Linux. Probably just need to remove the chown lines or find a Windows equivalent. – jdabney Apr 03 '12 at 18:25
  • Thank you for the script. I have test this on my PC by installing python. but I can't install python on server I have to look for powershell or vb script. – Lalajee Apr 04 '12 at 09:30
  • @Lalajee It is Python. – Lei Yang Mar 29 '16 at 02:47