Page 1 of 1 1
Topic Options
#124839 - 2004-08-12 08:16 PM FTPPUT()
Stanley Offline
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
#124840 - 2004-08-12 08:47 PM Re: FTPPUT()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Sorry, don't have an FTPPut() UDF for you but if you are nice to Jooel...

We like to consider ourselves KiXters and the vicarious leeches KixTarts.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124841 - 2004-08-12 09:25 PM Re: FTPPUT()
Stanley Offline
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
#124842 - 2004-08-12 09:37 PM Re: FTPPUT()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
check this:
http://home.comcast.net/~habullock/Win32Admin.htm#Miscellaneous

it's a part of admin-dll by hoby, one of our admins.

what comes to modding the udf, IIRC, it's not possible with that.
_________________________
!

download KiXnet

Top
#124843 - 2004-08-13 09:07 PM Re: FTPPUT()
Stanley Offline
Starting to like KiXtart

Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
Thanks, but I think I will go back to FTPPUT(). After wasting hours of my employers internet time I come to the conclusion you are correct you can't get there from here. It just frosts my backside that something as simple and beautiful as FTPGET() cannot be changed to work in reverse. ACK PFFFT!!!
_________________________
Taxation WITH representation isn't so hot, either!

Top
#124844 - 2004-08-13 10:11 PM Re: FTPPUT()
Bryce Offline
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 Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This looks really familiar to a discussion with Lonk..

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

Top
#124846 - 2004-08-14 03:36 AM Re: FTPPUT()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Converts to...

Error Code: 9 | The storage control block address is invalid.

Top
Page 1 of 1 1


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

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

Generated in 0.032 seconds in which 0.015 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