break on
cls
;debug onN:
CD "\Miscellaneous\Scheduled Jobs\Virus Def Update"
Call "\\ittbinghamt\x$\workarea\kix\BreakFile.udf"
Gosub InitVaribles
Gosub GetFTPDirList
Gosub GetServerFileSize
GoSub DeterminNewNavDef
If $NewNavUpdate = "Yes"
GoSub GetVirusUpdate
EndIf
Exit
;INITVARIBLES-------------------------------------------------------------
:InitVaribles
$ftpsite = "ftp.symantec.com"
$username = "anonymous"
$password = "guest@@guest.com"
$FTPdir = "/public/english_us_canada/antivirus_definitions/norton_antivirus/static"
$DownloadDir = "n:\Norton Anti Virus\Client Installations\NAVCE 7.6"
$NavUpdateFileName = "sarcx86.exe"
$NavUpdateFile = FileNotExt($NavUpdateFileName) ;fuction in Breakfile.udf
$NavUpdateExt = FileExt($NavUpdateFileName) ;fuction in Breakfile.udf
$cr = chr(13)+chr(10)
$FTPLogFile = "NAV.out"
$FTPScript = "NAVUpdate.ftp"
$NAVError = ""
$NewNavUpdate = "No"
RETURN
;DETERMINNEWNAVDEF-----------------------------------------------------
:DeterminNewNavDef
$NavLocalFileSize = GetFileSize($DownloadDir + "\" + $NavUpdateFileName)
If $RemoteFileSize > 0 and $RemoteFileSize <> $LocalFileSize ; there is a different file on the ftp site
$NewNavUpdate = "Yes"
Endif
$Tmp = close(1)
del $FTPLogFile
exit
;GETFTPDIRLIST----------------------------------------------------------------
:GetFTPDirList
$ftpcommand = "open $ftpsite$cr"+
"$username$cr"+
"$password$cr"+
"cd $ftpDir$cr"+
"dir $cr"+
"quit$cr"
$Tmp = open(10,"$FTPScript",5)
$Tmp = writeline(10,"$FTPCommand")
$Tmp = close(10)
shell "%comspec% /c ftp -s:$FTPScript > $FTPLogFile"
del "$FTPScript"
RETURN
;GETSERVERFILESIZE-------------------------------------------------------
;$RemoteFileSize = File size of sarcx86.exe on FTP server
:GetServerFileSize
$UpdateFoundInLog = "No" ;checking varible to check to see the nav update is actually found in the ftp log file.
$tmp = Open(1,$FTPLogFile,2)
$RemoteFileSize = 0
If $tmp = 0 ; File opened sucessfully
$LogLine = ReadLine(1)
Do
$LogLinePointer = Instr($LogLine,"$NavUpdateFileName") ;The position in the line of the start of the string sarcx86.exe
debug on
If $LogLinePointer > 0
debug on
$UpdateFoundInLog = "Yes"
? $LogLine
$LogLinePointer = $NAVLogLinePointer - 15 ;The file size value last char is 15 spaces from the start of the sarcx86.exe string
$cnt = 0
Do
$x = Substr($LogLine,$LogLinePointer - $cnt,1)
$cnt = $cnt + 1
Until $x = " "
$cnt = $cnt - 1
$RemoteFileSize = Substr($LogLine,$LogLinePointer - ($cnt-1),$cnt)
Else
$LogLine = ReadLine(1)
Endif
Until @Error<>0 or $LogLinePointer > 0
Close (1)
If UpdateFoundInLog = "No" ;$NavUpdateFileName was not found in the ftplogfile.....
debug on
$NavError = $NavError + "ERROR. Could not find $NavUpdateFileName within FTP LogFile($FTPLogFile)." + $CR
$NavError = $NavError + "Possible causes could be:" + $CR
$NavError = $NavError + " 1. A failure to FTP to $FTPSite" + $CR
$NavError = $NavError + " 2. A failure to change directories to $FTPdir at $FTPSite" + $CR
$NavError = $NavError + " 3. $NavUpdateFileName not found in $FTPdir at $FTPSite" + $CR
$NavError = $NavError + $CR + "Check $FTPLogFile for Error Outputs."
Goto NAVError
EndIf
Else ; Error opening $FTP Log File
Select
Case $Tmp = -3
$NavError = $NavError + "ERROR: $tmp. Error Opening $FTPLogFile. (Script Error, File number already in use)!" + $CR
Case $Tmp = -2
$NavError = $NavError + "ERROR: $tmp. Error Opening $FTPLogFile. (Script Error. Invalid File Number)!" + $CR
Case $Tmp = -1
$NavError = $NavError + "ERROR: $tmp. Error Opening $FTPLogFile. ($FTPLogFile Not found)!" + $CR
Case $Tmp >0
$NavError = $NavError + "ERROR: $tmp. Error Opening $FTPLogFile. (System Error: @SERROR)!" + $CR
EndSelect
Goto NAVError
Endif
Return
;-------------------------------------------------------------------------
:GetVirusUpdate
;ftp file down as .new
;If ftp was successfull (file exists)
Gosub BackupFiles
Return
;-------------------------------------------------------------------------
:GetFTPFile
$ftpcommand = 'open $ftpsite$cr'+
'$username$cr'+
'$password$cr'+
'cd $ftpDir$cr'+
'bin $cr'+
'get $ftpfile "$downloadDIR\Virus Definitions\$ftpfile.new"$cr'+
'quit$cr'
$Tmp = open(10,"$FTPScript",5)
$Tmp = writeline(10,"$FTPCommand")
$Tmp = close(10)
shell "%comspec% /c ftp -s:$FTPScript > $Nav"
del "Ftpcommand.tmp"
If getfilesize("$FTPScript") <> $RemoteFileSize ;Determined in :GetServerFileSize
$NavError = $NavError + "Error: The Downloaded $FTPFile is inconsitent with previous detemined size." + $CR
$NavError = $NavError + "Possible causes could be:" + $CR
$NavError = $NavError + " 1. The ftp process was interupted and an imcomplete $FTPFile was downloaded" + $CR
$NavError = $NavError + " 2. The $FTPFile has been updated since the script check its file size" + $CR + $CR
$NavError = $NavError + "Check $FTPLogFile for errors."
$NavError = $NavError + "The Downloaded $FTPFile is considered corrupt and will be deleted."
Goto NAVError
Endif
If Exist($NavUpdateFile + "(10).bak")
Del $NavUpdateFile + "(10).bak"
Endif
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(09).bak" "$NaveUpdateFile(10).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(08).bak" "$NaveUpdateFile(09).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(07).bak" "$NaveUpdateFile(08).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(06).bak" "$NaveUpdateFile(07).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(05).bak" "$NaveUpdateFile(06).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(04).bak" "$NaveUpdateFile(05).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(03).bak" "$NaveUpdateFile(04).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(02).bak" "$NaveUpdateFile(03).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile(01).bak" "$NaveUpdateFile(02).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile.exe" "$NaveUpdateFile(01).bak"'
SHELL '%COMSPEC% /c RENAME "$DownloadDir\Virus Definitions\$NaveUpdateFile.exe.new" "$NaveUpdateFile.exe"'
SHELL '%COMSPEC% /c sarcx86.exe virdef /EXTRACT /Q'
del $FTPScript
RETURN
;NAVERROR--------------------------------------------------------
:NAVError
? $NavError
EXIT