OK, there's something else going on.
Firstly don't worry about the file size staying at zero, IIRC the file size
doesn't get written until the download is finished.
I've tested this and it works fine.
The relevant piece of code I have in WriteHTTPDataToFile is :-
lngTotalBytesWritten = 0
'Read in MAX_CHUNK Chunk
Do
ReDim abytData(MAX_CHUNK)
lngRet = apiInetReadFile(hURL, _
abytData(0), _
MAX_CHUNK, _
lngBytesRead)
Call apiWriteFile(hFile, abytData(0), lngBytesRead, _
lngBytesWritten, 0&)
lngTotalBytesWritten = lngTotalBytesWritten + lngBytesWritten
Call SysCmd(acSysCmdUpdateMeter, CInt(lngTotalBytesWritten / mlngSize))
Loop Until lngRet <> 0 And lngBytesRead = 0
I'm call ing the routine as follows
Sub TestHTTP()
On Error GoTo ErrHandler
Dim objHTTP As InetTransferLib.HTTP
Const conTARGET = "http://www.mvps.org/access/acknowledge.htm"
Set objHTTP = New InetTransferLib.HTTP
With objHTTP
.HttpURL = conTARGET
.DestinationFile = "C:\test.htm"
If .FileExists Then .OverwriteTarget = True
.ConnectToHTTPHost
.WriteHTTPDataToFile
End With
ExitHere:
On Error Resume Next
Set objHTTP = Nothing
Call SysCmd(acSysCmdRemoveMeter)
Exit Sub
ErrHandler:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical + vbOKOnly,
Err.Source
Resume ExitHere
End Sub
and this works. (the file created is 73.5 kb).
In the WriteHTTPDataToFile procedure try keeping a track of
lngBytesRead this should be at most MAX_CHUNK
lngBytesWritten this should be at most lngBytesRead
lngTotalBytesWritten this should be at most the size of your file in
bytes.
--
Terry Kreft
"Hanspeter Leupin" <le***@csi.com> wrote in message
news:rw****************************@40tude.net...
Hi Terry,
Thanks for your replay.
On Fri, 6 Jan 2006 16:29:36 -0000, Terry Kreft wrote:
Call apiWriteFile(hFile, abytData(0), MAX_CHUNK, _
lngBytesWritten, 0&)
Which should be this
Call apiWriteFile(hFile, abytData(0), lngBytesRead, _
lngBytesWritten, 0&)
I replaced MAX_CHUNK with lngBytesRead... well the overflow error is
gone -
but the download of the file doesn't work. The code loops for ever at the
line where I did the change. The progress bar doesn't move and the
filesize
of my 20kb file stays at 0...
lngTotalBytesWritten = 0
'Read in MAX_CHUNK Chunk
Do
ReDim abytData(MAX_CHUNK)
lngRet = apiInetReadFile(hURL, abytData(0), MAX_CHUNK, lngBytesRead)
Call apiWriteFile(hFile, abytData(0), lngBytesRead, _
lngBytesWritten, 0&)
lngTotalBytesWritten = lngTotalBytesWritten + lngBytesWritten
Call SysCmd(acSysCmdUpdateMeter, CInt(lngTotalBytesWritten / mlngSize))
Loop Until lngRet <> 0 And lngBytesRead = 0
Any ideas or is there something missing ?
Hanspeter