;Function: FTPget()
;
;Authors: Lonkero
; kdyer
;
;Version: 1.2 (2th of August 2007)
;
;Version History:
; 1.2 - current, added Force-parameter
; 1.1 (6th of December 2002)
;
;Action: gets file from ftp or http server and saves it in specified file
;
;Syntax: FTPget("URL", "TARGET", "USERNAME", "PASSWORD", FORCE)
;
;Parameters:
; URL - full url to the file to get
; TARGET - full path to file where to save
; USERNAME- optional, specifies username to use in connection
; PASSWORD- optional, specifies password to use in connection
; FORCE - optional, force udf to bypass cache
;
;Returns:
; Nothing or errorcode on error.
;
; on error errorcodes returned and set:
; 1 -failed to initialize http-object
; 2 -failed to initialize ADODB-object
; 3 -failed to open connection
; 4 -ADO write failed
; 5 -save to file failed
;
;Dependencies:
; IE5 or higher
;
;Remarks:
; if file exists, it will be overwritten.
; not sure about the ado, dependency?
;
;Example:
; "Downloading TypelibViewer, Please standby..."
; if FTPget("http://www.rwksystems.com/files/TypeLibViewer.exe","%temp%\typelibViewer.exe")
; "error occured:" @error
; else
; "Download complete. file is saved in %temp% as typelibViewer.exe"
; endif
;
;Source:
Function FTPget($sURL, $sTargetFile, optional $sUser, $sPass, $iForce)
Dim $oFTP, $oStream,$dwSM,$,$sLoc
$sLoc="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$sUser=""+$sUser
if $iForce
$dwSM = Readvalue($sLoc,"Syncmode5")
$=writevalue($sLoc,"Syncmode5",3,"REG_DWORD")
endif
$oFTP = CreateObject("Microsoft.XMLHTTP")
if @error
$ftpget=1
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 1
endif
$oStream = CreateObject("ADODB.Stream")
if @error
$ftpget=2
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
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
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 3
endif
$oFTP.Send
$oStream.Type = 1
$oStream.Mode = 3
$oStream.open
$oStream.Write($oFTP.responseBody)
if @error
$ftpget=4
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 4
endif
$oStream.SaveToFile($sTargetFile, 2)
if @error
$ftpget=5
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 5
endif
$oFTP=0
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
$oStream.Close
EndFunction