Page 1 of 1 1
Topic Options
#194045 - 2009-05-29 01:23 AM Need to download from website in a script
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thought I had seen an UDF to allow the download of a file from a website. But can't seem to find it now.

Have to download a file from a website (they only make it available this way) once a month. The file name is always the same (except a scriptable portion of it).

Anybody know of an UDF or another way that I can do this.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194046 - 2009-05-29 01:43 AM Re: Need to download from website in a script [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
This one?
FTPGet() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83713

Top
#194047 - 2009-05-29 02:28 AM Re: Need to download from website in a script [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
See it was that FTP that got me....

Thanks.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194048 - 2009-05-29 02:30 AM Re: Need to download from website in a script [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well not sure if this works but here is something I put together back in early 2004
You can see if you can modify it and update it to work for your neeeds.
This code is NOT what I would consider production quality but it works

 Code:
Dim $URL,$Link,$RC,$Page,$Server,$File,$Download,$Target,$Wait,$Servers1,$Servers2,$FileSize
$URL='http://www.sarc.com/avcenter/download/pages/US-SAVCE.html'
$Link='http://definitions.symantec.com/defs/xdb/'
$RC=readHTML($URL)
$File=InStr($RC,$Link)
$File=SubStr($RC,$File+41,12)
$Download = $Link + $File
$Target='C:\DOWNLOAD\'
$Servers1='AV01','AV02','AV03','AV04'
$Servers2='D09','D17'
 
? 'Downloading ' + $File + '  Please wait...' 
If FTPget($Download,$Target+$File)
  ? 'Error occured: ' + @ERROR + ' ' + @SERROR
Else
  ? 'Download complete... File saved in ' + $Target + ' as ' + $File
	$FileSize = GetFileSize($Target+$File)
	If $FileSize >14000000
		? 'Ready to update AntiVirus Defs'
		? 'File size downloaded was: ' + $FileSize
	  For Each $Server In $Servers1
	    Copy $Target+$File '\\'+$Server+'\c$\PROGRA~1\SAV'
	    ? 'Copying to ' + $Server +'...  ' + @ERROR + ' ' + @SERROR
	  Next
	  For Each $Server In $Servers2
	    Copy $Target+$File '\\'+$Server+'\c$\PROGRA~1\NAV'
	    ? 'Copying to ' + $Server +'...  ' + @ERROR + ' ' + @SERROR
	  Next
	  ; This line archives the definition files to AV01 for reference
	  MOVE $Target+$File '\\av01\c$\XDB\OLDXDB'
	    ? 'Moving xdb file to AV01 archive  ' +@ERROR + ' ' + @SERROR
	    ? 'Definition updates completed...' 
	    ? 'Please press a key to continue...'
	Else
			? 'The file size appears to be too small.  Update aborted, please try later...'
			? 'File size was: ' + $FileSize
	EndIf
	?? 'Press a key to continue...'
  GET $Wait
EndIf

Function readHTML($page)
Dim $obj
 $obj=createobject("microsoft.xmlhttp")
 $obj.open("get",$page,not 1)
 $obj.send
 $readHTML=$obj.responsebody
EndFunction

Function FTPget($sURL, $sTargetFile, optional $sUser, optional $sPass)
  Dim $oFTP, $oStream
  $sUser=""+$sUser
  $oFTP = CreateObject("Microsoft.XMLHTTP")
  if @error $ftpget=1 exit 1 endif
  $oStream = CreateObject("ADODB.Stream")
  if @error $ftpget=2 exit 2 endif
  if $sUser
    $oFTP.Open("GET", $sURL, not 1, $sUser, $sPass)
  else
    $oFTP.Open("GET", $sURL, not 1)
  endif
  if @error $ftpget=3 exit 3 endif
  $oFTP.Send
  $oStream.Type = 1
  $oStream.Mode = 3
  $oStream.open
  $oStream.Write($oFTP.responseBody)
  if @error $ftpget=4 exit 4 endif
  $oStream.SaveToFile($sTargetFile, 2)
  if @error $ftpget=5 exit 5 endif
  $oStream.Close
EndFunction

Top
#194050 - 2009-05-29 11:48 AM Re: Need to download from website in a script [Re: NTDOC]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
A non-kix option is wget. I use it quite often to automate downloads from web pages.

http://www.gnu.org/software/wget/

Top
#194054 - 2009-05-29 06:26 PM Re: Need to download from website in a script [Re: BradV]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
So I started with the FTPget and now McAfee thinks it is a virus. How fun is that.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194055 - 2009-05-29 07:36 PM Re: Need to download from website in a script [Re: Gargoyle]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
So reading throught the thread on FTPget() I see that McAfee has had this issue before. Now they have to fix it yet again. Such fun. Have a ticket open with them now.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194056 - 2009-05-29 07:50 PM Re: Need to download from website in a script [Re: Gargoyle]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Found that by stripping off the ASE header info it would save without an issue (script settings region). But have run into the issue of getting error code 4 (unable to open connection). How can I debug what is causing this?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194129 - 2009-06-04 11:17 PM Re: Need to download from website in a script [Re: Gargoyle]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Any help guru's ? I still get the error code 4, from the UDF, but am unsure how to understand why it is unable to open the connection.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#194130 - 2009-06-04 11:33 PM Re: Need to download from website in a script [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I've never used it. Curious though... in the header it says error 4 is
"4 -ADO write failed". Not sure what that means either, but its different than "unable to open connection".

Top
#194131 - 2009-06-05 01:02 AM Re: Need to download from website in a script [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
http://support.microsoft.com/kb/870669
http://www.w3schools.com/ADO/ado_ref_stream.asp

Top
#194132 - 2009-06-05 01:07 AM Re: Need to download from website in a script [Re: NTDOC]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thanks Doc, I must have been googling the wrong keywords. Now Off I go to read some more.

Allen - Well I never claimed to be any good at lining things up..... \:\)


Edited by Gargoyle (2009-06-05 01:10 AM)
_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 1 of 1 1


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

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

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