This works great thank you Lonkero and Kdyer. How would I modify it to Put files from local to FTP site? i apologixe in advance if it seems like a foolish question but I am not a programming wiz just a novice KIXer...? KIXter...? KIXarian...?KXITarter...?.
I did find a UDF FTPPUT, but it uses a text file of commands passed to FTP and I already know how to do that.
Code:
;Function: FTPget()
;
;Authors: Lonkero
; kdyer
;
;Version: 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")
;
;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
;
;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:
BREAK ON CLS
$ = FTPGET("ftp://svr.domain.com/share/test.txt","C:\_ftp\test.txt","domain\user","password")
?$
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
;Set transfer as binary
$oStream.Type = 1
;Prevents others from opening a connection with read permissions.
$oStream.Mode = 3
$oStream.open
;? "SERROR: @SERROR"
$oStream.Write($oFTP.responseBody)
IF @error $ftpget=4 ? "SERROR: @SERROR" EXIT 4 ENDIF
$oStream.SaveToFile($sTargetFile, 2)
IF @error $ftpget=5 EXIT 5 ENDIF
$oStream.Close
ENDFUNCTION