Page 1 of 1 1
Topic Options
#17634 - 2002-02-19 03:00 PM ftp file version check
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
I am looking to write a script that checks a ftp site for a specific file and if it has changed. IF the file has changed pull down the file to a specific diretory. I have searched the message board and cant find any thing close to this. Has any one done this before and if so can you point me in the right direction.

the file I'm checking is about 2.4Megs so I dont want to pull the file down each time I check it.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#17635 - 2002-02-19 03:36 PM Re: ftp file version check
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
I have found some useful info. in an ftp session if I do a dir *.exe data.txt, this will write the directory contents with the datestamp to a local file data.txt. Now I just need to parse the text file.
_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#17636 - 2002-02-19 03:47 PM Re: ftp file version check
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jason,

Have a look at the batch script that was created that does this for ftp.mcafee.com.

Check if FTP file has changed

Here is an updated version that not only checks for a new version, but gets it.

FTP File Check

We have used this with ePO (ePolicy Orchestrator) for about a year and a half with no problems.

HTH,

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#17637 - 2002-02-20 03:30 AM Re: ftp file version check
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
thanks for the link. I took a wack at creating my own kixtart script, you can do so much more with kixtart. I need to add a loop for failed logins to the ftp server but it works well.

; Kixtart script for retrieving
; latest superdat file from McaFee's
; FTP site.
; 02/19/02 by Jason Hammond
;
$userlogin="anonymous" ; user name for ftp.nai.com
$userpass="youraddress@yourdomain.com" ; email address
$ftpdir="/pub/antivirus/superdat/intel"
$ftpsite="ftp.nai.com"
$ftpbat="ftp.scr"
$loc="c:\ftp" ; location of script files
; and flag file

Break ON
Shell "%COMSPEC% /C ftp -s:" + $loc + "\" + $ftpbat
If Not Exist($loc + "\vcheck.txt")
Shell "%COMSPEC% /c copy $loc\vcheck.txt $loc\current.log"
If not Exist($loc + "\vcheck.txt")
? "ftp login failed" ; Im working on adding a loop to
; try loggin in again.
Goto End
EndIf
EndIf

If Open(1, $loc + "\vcheck.txt") =0
$vcheck = ReadLine(1)
If Open(2, $loc + "\current.log") =0
$current = ReadLine(2)
If $vcheck <> $current
$version=$vcheck
Close (1)
Close (2)
Shell "%COMSPEC% /c copy $loc\vcheck.txt $loc\current.log"
Goto Download
EndIf
EndIf
EndIf
Goto End

ownload
If Exist($loc + "\ftpget.scr")
Del "$loc\ftpget.scr"
EndIf
Shell "%COMSPEC% /c echo open $ftpsite >$loc\ftpget.scr"
Shell "%COMSPEC% /c echo $userlogin >> $loc\ftpget.scr"
Shell "%COMSPEC% /c echo $userpass >> $loc\ftpget.scr"
Shell "%COMSPEC% /c echo CD $ftpdir >> $loc\ftpget.scr"
Shell "%COMSPEC% /c echo lcd $loc >> $loc\ftpget.scr"
Shell "%COMSPEC% /c echo get $version >> $loc\ftpget.scr"
Shell "%COMSPEC% /c echo bye >> $loc\ftpget.scr"
Shell "%COMSPEC% /c ftp -s:$loc\ftpget.scr"
:End

contents of ftp.scr

open ftp.nai.com
anonymous
youremail@yourdomain
cd /pub/antivirus/superdat/intel
dir s*.exe c:\ftp\currentd.txt
ls s*.exe c:\ftp\vcheck.txt
bye

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#17638 - 2002-02-20 04:20 AM Re: ftp file version check
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jason,
Another way to generate ftpget.scr without all that SHELLing out is to use RedirectOutput().
code:

If RedirectOutput($loc + "\ftpget.scr") = 0
"open " + $ftpsite ?
$userlogin ?
$userpass ?
"CD " + $ftpdir ?
"lcd " + $loc ?
"get " + $version ?
"bye" ?
$rc = RedirectOutput("")
Endif

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#17639 - 2002-02-20 09:38 AM Re: ftp file version check
Anonymous
Unregistered


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 ]

Top
#17640 - 2002-02-20 09:53 AM Re: ftp file version check
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa

Wow you sure put some serious time into that script. Thanks for posting that, there is some syntax that you are using that I didnt realize you could do. I have it easy since mcafee's superdat files are numbered sdat4168, especially since I have heard pulling version info, date,time etc can sometimes be unreliable from ftp sites.

thanks again.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.063 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org