#124839 - 2004-08-12 08:16 PM
FTPPUT()
|
Stanley
Starting to like KiXtart
Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
|
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
Edited by Stanley (2004-08-12 08:39 PM)
_________________________
Taxation WITH representation isn't so hot, either!
|
|
Top
|
|
|
|
#124841 - 2004-08-12 09:25 PM
Re: FTPPUT()
|
Stanley
Starting to like KiXtart
Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
|
Thanks Les. Hopefully I am considered a KIXTer. Running KIX v4.22 W2kPro I tried changes as follows (See CODE below).
ERROR 2567/80020009 ]f acceptable range, or are in conflict with one another.) [-2147354 ERROR
The error appears to be truncated. Is this due to my code or something else? It would also help me if someone could clarify what exactly is happening here. Code:
$oStream.Write($oFTP.responseBody)
Code:
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
_________________________
Taxation WITH representation isn't so hot, either!
|
|
Top
|
|
|
|
#124844 - 2004-08-13 10:11 PM
Re: FTPPUT()
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
i have been working on it.... but something is missing.....
Code:
Function PutFile($lFile,$sfile,optional $user,optional $pass)
DIM $xmlhttp
DIM $objStream
$xmlhttp = CreateObject("Microsoft.XMLHTTP")
$objStream = CreateObject("ADODB.Stream")
$objStream.Type = 1 ; adTypeBinary
$objStream.Open
$objStream.LoadFromFile($lFile)
? $sfile
If $User
$xmlhttp.Open("PUT",$sfile, not 1, $user, $Pass)
Else
$xmlhttp.Open("PUT",$sfile, not 1)
EndIf
$xmlhttp.Send($objStream.Read)
? @ERROR " " @SERROR
EndFunction
the $xmlhttp.Send($objStream.Read) pauses like it is sending data.... but then it returns a error....
Quote:
-2147352567 COM exception error "Send" ((null) - (null)) [-2147352567/80020009]
[/qoute]
Edited by Bryce (2004-08-13 10:28 PM)
|
|
Top
|
|
|
|
#124845 - 2004-08-13 10:31 PM
Re: FTPPUT()
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
This looks really familiar to a discussion with Lonk..
Kent
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1707 anonymous users online.
|
|
|