Hi, I am facing a problem related to InternetWriteFile of WININET API. I am in the process of developing a FTP program, which periodically check a local directory and uploads the any few files available in that directory. I am using Wininet (internetwritefile) to transfer for the file. I am able to show the progress also. The problem comes only when there is connection error/break while file transfer. The execution never stops (probably it doesn't get timed out). How to overcome this problem? I want to return an error when the data flow is obstructed for about certain amount of time and restart the entire process after sometime. Currently my application gets hanged. Any sort of help is appreciated. Here is my code: hFile = FtpOpenFile(hConnection, szFileRemote, &H40000000, dwType, 0) If hFile = 0 Then ErrorOut Err.LastDllError, "FtpOpenFile" Txtstr.WriteLine "Unable to open file on remote server" GoTo CloseObjects End If Open CurFile For Binary Access Read As #1 Size = LOF(1) For j = 1 To Size \ 100 Get #1, , Data If (InternetWriteFile(hFile, Data(0), 100, Written) = 0) Then Close #1 ErrorOut Err.LastDllError, "InternetWriteFile" GoTo CloseObjects End If DoEvents sum = sum + 100 Sbar.Panels(1).Text = CStr(Round((sum * 100) / lLocalflsize)) & "%" DoEvents Pbar1.Value = sum Next j If Size Mod 100 <> 0 Then Get #1, , Data If (InternetWriteFile(hFile, Data(0), Size Mod 100, Written) = 0) Then Close #1 ErrorOut Err.LastDllError, "InternetWriteFile" GoTo CloseObjects End If 'internet file End If 'If Size Mod 100 <> 0 sum = sum + (Size Mod 100) Sbar.Panels(1).Text = CStr(Round((sum * 100) / lLocalflsize)) & "%" Close #1 InternetCloseHandle (hFile) Thanks M.L.Srinivas
|