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