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.

4

1 回答 1

1

我实际上已经这样做了。我已经有一两年没有测试过这个脚本了,但这就是我正在使用的。这不是用 Powershell 编写的,但如果您更改目录,我认为这可以在 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()
于 2012-04-03T09:35:55.347 回答