MLSrinivas
2005-01-21 08:01:34 UTC
Hi all,
I'm having problem while downloading larger files (larger than 3 MB). I'm
wininet API and InternetReadFile to download the file. I'm using
InternetReadFile so that I can download the file in chunks and a progress
bar can be showed.
I have no problem with smaller files up to 3MB. Can anybody show me a way
out? What could be the problem?
Here's is my code:
Dim hFile As Long
Dim strCommand As String
strCommand = "REST 5"
bRet = FtpCommand(hConnection, False, FTP_TRANSFER_TYPE_ASCII,
strCommand, 0, hFile)
DoEvents
strCommand = "REST 0"
bRet = FtpCommand(hConnection, False, FTP_TRANSFER_TYPE_ASCII,
strCommand, 0, hFile)
DoEvents
strCommand = "RETR " & szDirRemote & szFileRemote
bRet = FtpCommand(hConnection, True, dwType, strCommand, 0, hFile)
DoEvents
Dim bDoLoop As Boolean
Dim sReadBuffer As String * 100
Dim lNumberOfBytesRead As Long
Dim sBuffer As String
' Open local file for writing
Dim F1 As Integer, j As Integer, sum As Long
F1 = FreeFile
Open szFileLocal & "\" & szFileRemote For Binary As F1
Size = FileSize 'filesize of remote
Pbar.Min = 0
Pbar.Max = Size
bDoLoop = True
For j = 1 To Size \ 100
sReadBuffer = vbNullString
bDoLoop = InternetReadFile(hFile, sReadBuffer, 100,
lNumberOfBytesRead)
Put F1, , sReadBuffer
If Not CBool(lNumberOfBytesRead) Then Exit For
DoEvents
sum = sum + 100
SBar.Panels(2).Text = CStr(Round((sum * 100) / Size)) & "%"
DoEvents
Pbar.Value = sum
DoEvents
Next j
If Size Mod 100 <> 0 Then
sReadBuffer = vbNullString
bDoLoop = InternetReadFile(hFile, sReadBuffer, Size Mod 100,
lNumberOfBytesRead)
Put F1, , sReadBuffer
If Not CBool(lNumberOfBytesRead) Then MsgBox "Error in retrieving
the image", vbInformation, "MEDantex"
End If
sum = sum + (Size Mod 100)
Pbar.Value = sum
SBar.Panels(2).Text = CStr(Round((sum * 100) / Size)) & "%"
Close F1
Please help.
M.L.Srinivas
I'm having problem while downloading larger files (larger than 3 MB). I'm
wininet API and InternetReadFile to download the file. I'm using
InternetReadFile so that I can download the file in chunks and a progress
bar can be showed.
I have no problem with smaller files up to 3MB. Can anybody show me a way
out? What could be the problem?
Here's is my code:
Dim hFile As Long
Dim strCommand As String
strCommand = "REST 5"
bRet = FtpCommand(hConnection, False, FTP_TRANSFER_TYPE_ASCII,
strCommand, 0, hFile)
DoEvents
strCommand = "REST 0"
bRet = FtpCommand(hConnection, False, FTP_TRANSFER_TYPE_ASCII,
strCommand, 0, hFile)
DoEvents
strCommand = "RETR " & szDirRemote & szFileRemote
bRet = FtpCommand(hConnection, True, dwType, strCommand, 0, hFile)
DoEvents
Dim bDoLoop As Boolean
Dim sReadBuffer As String * 100
Dim lNumberOfBytesRead As Long
Dim sBuffer As String
' Open local file for writing
Dim F1 As Integer, j As Integer, sum As Long
F1 = FreeFile
Open szFileLocal & "\" & szFileRemote For Binary As F1
Size = FileSize 'filesize of remote
Pbar.Min = 0
Pbar.Max = Size
bDoLoop = True
For j = 1 To Size \ 100
sReadBuffer = vbNullString
bDoLoop = InternetReadFile(hFile, sReadBuffer, 100,
lNumberOfBytesRead)
Put F1, , sReadBuffer
If Not CBool(lNumberOfBytesRead) Then Exit For
DoEvents
sum = sum + 100
SBar.Panels(2).Text = CStr(Round((sum * 100) / Size)) & "%"
DoEvents
Pbar.Value = sum
DoEvents
Next j
If Size Mod 100 <> 0 Then
sReadBuffer = vbNullString
bDoLoop = InternetReadFile(hFile, sReadBuffer, Size Mod 100,
lNumberOfBytesRead)
Put F1, , sReadBuffer
If Not CBool(lNumberOfBytesRead) Then MsgBox "Error in retrieving
the image", vbInformation, "MEDantex"
End If
sum = sum + (Size Mod 100)
Pbar.Value = sum
SBar.Panels(2).Text = CStr(Round((sum * 100) / Size)) & "%"
Close F1
Please help.
M.L.Srinivas