Page 3 of 4 <1234>
Topic Options
#89905 - 2002-12-04 05:06 PM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh, so ado is not working?
thought you were the one from us who knows that part [Wink]
_________________________
!

download KiXnet

Top
#89906 - 2002-12-05 06:57 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Did some more digging..

Found some Micheal Harris posts on Google (old Deja) Groups.

Stream.Write Buffer

Is what we need to be focusing on-

Stream Object

Thanks,

Kent

[ 05. December 2002, 07:01: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#89907 - 2002-12-05 07:01 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
steam?
as in sauna?
_________________________
!

download KiXnet

Top
#89908 - 2002-12-05 07:02 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doh!

Yeah.. I could use one of those right now!

Wanna send me one?

Seriously, it is Stream.

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

Top
#89909 - 2002-12-05 07:05 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm, dunno. responsebody should do that...

mm... yep, stream goes for binary.
but when reading, responsebody handles both, binary and text... auto-mode may I say...
_________________________
!

download KiXnet

Top
#89910 - 2002-12-05 07:06 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I'll dig up more that ADO stuff once I get to work.
been trying to leave for 3 hours unsuccessfully.
_________________________
!

download KiXnet

Top
#89911 - 2002-12-06 05:17 PM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What we appear to need is a method that converts to binary for file transfer.

Neither of these methods work:

Method (1) conversion to Binary using multi-part form data
code:
if WinHTTPPostRequest("ftp://ftpsite/kdyer/kdyer", "c:\cr.dbf","kdyer","pw")
?"error occured:" @error
sleep 2
else
?"upload complete."
sleep 2
endif

Function WinHTTPPostRequest($sURL, $sFile, $uid, $pw)
; http://www.pstruh.cz/tips/detpg_post-binary-data-url.htm
Dim $http ;As New MSXML2.XMLHTTP

;Create XMLHTTP/ServerXMLHTTP/WinHttprequest object
;You can use any of these three objects.
;$http = CreateObject("WinHttp.WinHttprequest.5")
$http = CreateObject("MSXML2.XMLHTTP")
;$http = CreateObject("MSXML2.ServerXMLHTTP")
if @error $WinHTTPPostRequest=1 exit 1 endif

;Open URL As POST request
$http.Open("POST", $sURL, not 1, $uid, $pw)
if @error $WinHTTPPostRequest=2 exit 2 endif

;Set Content-Type header
$http.setRequestHeader("Content-Type", "multipart/form-data")
;$http.setRequestHeader("Content-Type", "multipart/form-data; boundary=
; >> Broken to two lines
;---------------------------15124220632234")
if @error $WinHTTPPostRequest=2 exit 2 endif

;Send the form data To URL As POST binary request
$http.send($sFile)
if @error $WinHTTPPostRequest=3 exit 3 endif

;Get a result of the script which has received upload
$WinHTTPPostRequest = $http.responseText
EndFunction

Method (2) LoadFromFile

Fails on LoadFromFile, position 5..

code:
if FTPPut("ftp://ftpserver/kdyer/kdyer", "c:\cr.dbf","uid","pw")
?"error occured:" @error
sleep 2
else
?"upload complete."
sleep 2
endif

Function FTPPut($sFile, $sURL, $uid, $pw)
Dim $oFTP, $oStream
$oFTP = CreateObject("Microsoft.XMLHTTP")
if @error $ftpput=1 exit 1 endif
$oStream = CreateObject("ADODB.Stream")
if @error $ftpput=2 exit 2 endif
$oStream.Type = 1
if @error $ftpput=3 exit 3 endif
$oStream.Open
if @error $ftpput=4 exit 4 endif
$oStream.LoadFromFile($sFile)
if @error $ftpput=5 exit 5 endif
$oFTP.Open("put", $sURL, not 1, $uid, $pw)
if @error $ftpput=6 exit 6 endif
;$oFTP.Send
;$oStream.setRequestHeader("Content-type", "image/jpeg")
;if @error $ftpput=5 exit 5 endif
$oFTP.Send($oStream.Read)
;$oStream.Mode = 3
;$oStream.open
;$oStream.Write($oFTP.responseBody)
;$oStream.SaveToFile($sFile, 2)
if @error $ftpput=5 exit 5 endif
$oStream.Close
EndFunction

Method (3) Function to generate Binary data
Did some prowling around on the web and found the following bit of code.

But fails on:

$lngNumber1 = $intDecimal / 2

Hmmm..
code:
break on
;ref - http://cwashington.netreach.net/depo/view.asp?Index=622&ScriptType=vbscript

$filename = "c:\cr.dbf"

$oFS = CreateObject("Scripting.FileSystemObject")
$File = $oFS.OpenTextFile($filename, 1, not 1, 0)

$Buffer = $File.Read(4)

$String = cbyte(asc($Buffer))

decimalToBinary($String)

Function decimalToBinary($intDecimal)
$strBinary = ""
$intDecimal = cInt($intDecimal)
While ($intDecimal > 1)
$lngNumber1 = $intDecimal / 2
$lngNumber2 = Fix($lngNumber1)
If ($lngNumber1 > $lngNumber2)
$strDigit = "1"
Else
$strDigit = "0"
EndIf
$strBinary = $strDigit + $strBinary
$intDecimal = Fix($intDecimal / 2)
Loop
$strBinary = "1" & $strBinary
While Len($strBinary) < 8
$strBinary = "0" + $strBinary
Loop
$binString = $strBinary
EndFunction

Thanks,

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

Top
#89912 - 2002-12-06 05:25 PM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
kent, 1 can be skipped.
2 has the problem of ado not working and it still seems to be the best to use...
_________________________
!

download KiXnet

Top
#89913 - 2002-12-06 05:28 PM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
should we skip the ado for moment and make the transfer happen with simple text-file?
this way it's problems do affect this.

anyway, is the multipart-form correct mime as it sais here is submit to you...
it should also have...
not sure but used on real form-data with vars and such...
_________________________
!

download KiXnet

Top
#89914 - 2002-12-06 05:39 PM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
also, does it work with no priv if set to anonymous?
I think xmlhttp does this automatically but uses the same anonymous stuff than ie:
ieuser@

which is not supported by most of real ftp sites.
_________________________
!

download KiXnet

Top
#89915 - 2002-12-10 08:57 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jooel,

Yes, we have now skipped ADO and have gone to a different methodology. Now, we need to get Public Function, Alias, and ByVal nailed down.

Here is what I have so far:
code:
 BREAK ON
CLS
; Ref - http://www.geocities.co.jp/SiliconValley/4805/vbtips/vbtips103.htm
FtpPut("ftp://ftpserver","kdyer","pw","ftp://ftpserver/kdyer/kdyer/test.jpg","c:\untitled1.jpg")
FUNCTION FtpPut($strftpsvr, $struserid, $strpassword, $strremotefile, $strlocalfile)
DIM $hinternet
DIM $hftp
DIM $lngret
DIM $strerrtext

$ftpput = True

IF @Error <> 0
GOTO ErrHandler
ENDIF

;INTERNET_OPEN_TYPE_PRECONFIG = 0&
$hinternet = InternetOpen("",0&,"","",0&)
IF $hinternet = 0
$strerrtext = "InternetOpen:GetLastError=" + $err.lastdllerror()
MESSAGEBOX ($strerrtext, $app.title + "<FtpPut>", 0)
$ftpput = NOT 1
RETURN
ENDIF

;INTERNET_DEFAULT_FTP_PORT = 21&
;INTERNET_SERVICE_FTP = 1&
$hftp = InternetConnect($hinternet, _
$strftpsvr, _
21&, _
$struserid, _
$strpassword, _
1&, _
0&, _
0&)
IF $hftp = 0
$strerrtext = "InternetConnect:GetLastError=" + $err.lastdllerror()
MESSAGEBOX($strerrtext, $app.title + "<FtpPut>", 0)
$ftpput = NOT 1
RETURN
ENDIF

;FTP_TRANSFER_TYPE_BINARY = &H2&
$lngret = FtpPutFile($hftp, _
$strlocalfile, _
$strremotefile, _
&H2&, _
0&)
$lngret = InternetCloseHandle($hftp)
$lngret = InternetCloseHandle($hinternet)
RETURN
:ErrHandler
$ftpput = NOT 1
MESSAGEBOX( "<" + $err + ">" + Error($err), $app.title + "<FtpPut>", 0 )
ENDFUNCTION

;-------------------------------------------------------
; Module
;-------------------------------------------------------
;constants
;INTERNET_OPEN_TYPE_PRECONFIG = 0&
;INTERNET_OPEN_TYPE_DIRECT = 1&
;INTERNET_OPEN_TYPE_PROXY = 3&
;INTERNET_DEFAULT_FTP_PORT = 21&
;INTERNET_DEFAULT_HTTP_PORT = 80&
;INTERNET_DEFAULT_HTTPS_PORT = 443&
;INTERNET_SERVICE_FTP As = 1&
;INTERNET_SERVICE_HTTP = 3&
;INTERNET_FLAG_PASSIVE = &H8000000
;INTERNET_FLAG_RELOAD = &H80000000
;FTP_TRANSFER_TYPE_ASCII = &H1&
;FTP_TRANSFER_TYPE_BINARY = &H2&

;API??

FUNCTION InternetOpen(Add($lpszAgent,"WinInet.DLL"),Add($dwAccessType,"WinInet.DLL"),
Add($lpszProxyName,"WinInet.DLL"),Add($lpszProxyBypass,"WinInet.DLL"0,Add($dwFlags,"WinInet.DLL")
; ;$inetopcstr = "wininet.dll"
; ;$inetopcstr = $inetopcstr + "InternetOpenA" + chr(40)
; $inetopcstr = $inetopcstr + Add($lpszAgent,"WinInet.DLL") + chr(44)
; $inetopcstr = $inetopcstr + Add($dwAccessType,"WinInet.DLL") + chr(44)
; $inetopcstr = $inetopcstr + Add($lpszProxyName,"WinInet.DLL") + chr(44)
; $inetopcstr = $inetopcstr + Add($lpszProxyBypass,"WinInet.DLL") + chr(44)
; $inetopcstr = $inetopcstr + Add($dwFlags,"WinInet.DLL")
ENDFUNCTION

FUNCTION InternetConnect($inetcstr)
$inetcstr = "WinInet.DLL"
$inetcstr = $inetcstr + "InternetConnectA" + chr(40)
$inetcstr = $inetcstr + Add($hInternetSession,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($lpszServerName,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($nServerPort,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($lpszUserName,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($lpszPassword,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($dwService,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($dwFlags,"WinInet.DLL") + chr(44)
$inetcstr = $inetcstr + Add($dwContext,"WinInet.DLL") + chr(41)
ENDFUNCTION

FUNCTION FtpPutFile($inetftpput)
$inetftpput = "wininet.dll"
$inetftpput = $inetftpput + "FtpPutFileA" + chr(40)
$inetftpput = $inetftpput + Add($hFtpSession,"WinInet.DLL") + chr(44)
$inetftpput = $inetftpput + Add($lpszLocalFile,"WinInet.DLL") + chr(44)
$inetftpput = $inetftpput + Add($lpszNewRemoteFile,"WinInet.DLL") + chr(44)
$inetftpput = $inetftpput + Add($dwFlags,"WinInet.DLL") + chr(44)
$inetftpput = $inetftpput + Add($dwContext,"WinInet.DLL") + chr(41)
ENDFUNCTION

FUNCTION InternetCloseHandle($inetclose)
$inetclose = "wininet.dll"
$inetclose = $inetclose + Add($hInternetSession,"WinInet.DLL") + chr(41)
ENDFUNCTION

; - Function Add is from Shawn Tassie since byval is not supported by KiX
; - ref - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=13;t=000017
FUNCTION Add($var1,$var2byref)
;
; Add Var1 to Var2 (byref) and put result back into Var2 (byref)
;
$ = Execute("$Var2ByRef = $Var1 + $Var2ByRef") ; do it
ENDFUNCTION

Thanks,

Kent

[ 10. December 2002, 08:58: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#89916 - 2002-12-10 09:06 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
will see.
are you sure it has to be that long?
the ado method was a lot shorter [Wink]
or was it just because it didn't work [Razz]
_________________________
!

download KiXnet

Top
#89917 - 2002-12-10 09:12 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
You can get LoadFromFile or...

Untested code... [Smile]

code:
break on

$file = "C:\AspEmail.dll"

ToBin($file)

Function StrConvert($vBin)
$oConv = CreateObject("ADODB.Stream")
$oConv.Charset = "utf-8"
$oConv.Type = 1 ;binary
$oConv.Open
$oConv.Write($vBin)
$oConv.Position = 0
$oConv.Type = 2 ;Text
$oConv.Charset = "Windows-1252" ;optionally
$StrConvert = $oConv.ReadText()
EndFunction

Or..
code:
Function ToBin($sString)
$oConv = CreateObject("ADODB.Stream")
$oConv.Charset = "Windows-1252"
$oConv.Type = 2 ; text
$oConv.Open
$oConv.WriteText($sString)
$oConv.Position = 0
$oConv.Type = 1 ;binary
;$oConv.Charset = "utf-8" ;optionally
$ToBin = $oConv.Read()
EndFunction

Working, please help yourself. [Big Grin]

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

Top
#89918 - 2002-12-10 09:20 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
converting to string?
no binary transfer?
_________________________
!

download KiXnet

Top
#89919 - 2002-12-10 09:26 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
As you may notice there are two different ones..

ToBin()
ToStr()

[Wink]

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

Top
#89920 - 2002-12-10 09:28 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, didn't read tobin() before reply [Embarrassed]
_________________________
!

download KiXnet

Top
#89921 - 2002-12-10 09:37 AM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
OK..

Here is some more information in my notes on this (probably nothing revolutionary, but maybe helpful):
quote:

Important The FTP protocol uses a single string that includes the =
operation name and any other parameters needed by the operation. In =
other words, the data and requestHeaders arguments are not used; all of =
the operations and their parameters are passed as a single string in the =
operation argument. Parameters are separated by a space. In the =
descriptions below, do not confuse the terms "file1" and "file2" with =
the data and requestHeaders arguments.

The syntax for FTP operations is:

operationName file1 file2.

For example, to get a file, the following code invokes the Execute =
method, which includes the operation name ("GET"), and the two file =
names required by the operation:

Inet1.Execute "FTP://ftp.microsoft.com", _
"GET Disclaimer.txt C:\Temp\Disclaimer.txt"
Note File names that include embedded spaces are not supported.

I did see -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusinginternettransfercontrol.asp

Notice that it uses Inet1

Hmmm..

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

Top
#89922 - 2002-12-10 09:44 AM Re: FTP via InetCtls.Inet.1
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Add($lpszProxyName,"WinInet.DLL"),Add($lpszProxyBypass,"WinInet.DLL"0,Add($dwFlags,"WinInet.DLL")

should this be kixtart? if yes, there is syntax error...
going for cigarette
_________________________
!

download KiXnet

Top
#89923 - 2002-12-10 06:29 PM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I know.. I was trying to do a work-around.. I was reading what Shawn and New Mexico Mark were doing with byVal.

Hmm..

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

Top
#89924 - 2002-12-10 06:33 PM Re: FTP via InetCtls.Inet.1
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
For those who may have a challenge of reading the last bit of code in Japanese -

[URL=http://msdn.microsoft.com/code/default.asp?url=/msdn-files/026/001/985/Server%20Components/Visual%20Basic%20COM/FBLL%20(Fullfillment%20Business%20Logic%20Layer)/winine t_bas.asp]

May help.

{Edit}
Tried to get the URL to display right.. [Frown]

Kent

[ 10. December 2002, 18:39: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 3 of 4 <1234>


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

Who's Online
1 registered (Allen) and 566 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.025 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