#89906 - 2002-12-05 06:57 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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 ]
|
Top
|
|
|
|
#89908 - 2002-12-05 07:02 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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
|
Top
|
|
|
|
#89911 - 2002-12-06 05:17 PM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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
|
Top
|
|
|
|
#89915 - 2002-12-10 08:57 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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 ]
|
Top
|
|
|
|
#89917 - 2002-12-10 09:12 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
You can get LoadFromFile or...
Untested code...
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.
Kent
|
Top
|
|
|
|
#89919 - 2002-12-10 09:26 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
As you may notice there are two different ones..
ToBin() ToStr()
Kent
|
Top
|
|
|
|
#89921 - 2002-12-10 09:37 AM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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
|
Top
|
|
|
|
#89923 - 2002-12-10 06:29 PM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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
|
Top
|
|
|
|
#89924 - 2002-12-10 06:33 PM
Re: FTP via InetCtls.Inet.1
|
Kdyer
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..
Kent [ 10. December 2002, 18:39: Message edited by: kdyer ]
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 566 anonymous users online.
|
|
|