Hello,

I dont want to confuse the issues but this is something that I have been working on for quite some time but never got around to finishing. I wanted to acheive exactly the same thing, check an FTP site (symantec) for a changed definition file and download it if the date and time is different to what was previously downloaded.

Although this is not a working script (to be honest, I can't even remember where I am up to), you may get some idea's behind what I have done (specifically the "DeterminNewNavDef" section). Like I said before, I hope I am not confusing you.

I should note that I have taken snippets out of an FTP script that I got of this board (I think it was Bryce's). Appologies for not knowing...
Terry.


code:

break on
cls
;debug on

N:
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


Here is BreakFile.udf

code:
 
Function FileExt($FileName)
$DotPoint = instr($filename,".")
If $DotPoint > 0
$FileExt = SubStr($FileName,$DotPoint+1,Len($FileName) - $DotPoint)
Else
$FileExt = ""
Endif
Endfunction

Function FileNotExt($FileName)
$DotPoint = instr($filename,".")
If $DotPoint > 0
$FileNotExt = SubStr($FileName,1,$DotPoint-1)
Else
$FileNotExt = ""
Endif
EndFunction


[ 20 February 2002: Message edited by: binghamt ]