Hi,

I've made a program using the INET control to login to a ftp host, change to a specific directory, download any files that are located in this directory, and then delete these files.

The funny thing is, this works great when there are files in this directory and does everything that it is supposed to do, however, if the directory is empty, my program waits for about a minute before figuring out that there are no files. I can't seem to figure out what is causing this problem at all.

This is the routine which retrieves the contents of the ftp directory. It is the routine which hangs for almost a minute every time there is no files in the directory.

VB Code:
  1. Public Function FTPGetDirectoryList() As Boolean
  2.     'Refreshed the remote directory listing
  3.     On Error GoTo FTPGetDirectoryListError
  4.  
  5.     Do Until inetReady(False)
  6.         DoEvents
  7.     Loop
  8.      
  9.     FTPGetDirectoryList = True
  10.     Call SendCommand("DIR")
  11.    
  12.     Exit Function
  13.        
  14. FTPGetDirectoryListError:
  15.  
  16.     FTPGetDirectoryList = False
  17.     MsgBox Err.Source & " " & Err.Number & " " & Err.Description
  18.    
  19. End Function

And this is where the incoming file names are retrieved. For clarity sake, I took out all the code for the other 'states', which only display a message in the form title bar.

VB Code:
  1. Private Sub Inet1_StateChanged(ByVal State As Integer)
  2.     With frmOOCModule
  3.  
  4.     Dim Data1 As String, Data2 As String
  5.    
  6.     Select Case State
  7.         Case icResponseCompleted
  8.             .Caption = "Request completed, all data received"
  9.            
  10.             'Loop until you get all chunks
  11.             Do While True
  12.                 'Change datatype to icByteArray to receive data in binary
  13.                 Data1 = Inet1.GetChunk(512, icString)
  14.                 'MsgBox "Data: " & Data1
  15.                 If Len(Data1) = 0 Then Exit Do
  16.                 DoEvents 'Transfer control to operating system
  17.                 Data2 = Data2 & Data1
  18.             Loop
  19.            
  20.             'MsgBox "Data2: " & Data2
  21.            
  22.             If Len(Data2) > 0 Then
  23.                 'Keep track of the file names received, as well as the file count
  24.                 Erase strFTPFiles
  25.                 strFTPFiles = Split(Data2, vbCrLf)
  26.                 numFTPFiles = UBound(strFTPFiles) + 1
  27.            
  28.                 'Dim i As Integer
  29.                 'For i = 1 To numFTPFiles
  30.                 '    MsgBox "File Name: " & strFTPFiles(i)
  31.                 'Next i
  32.             End If
  33.         Case Else
  34.             .Caption = "Unknown Error!"
  35.     End Select
  36.     If frmOptions.Inet1.StillExecuting Then .Caption = .Caption & ". Please wait..."
  37.     End With
  38. End Sub

Does anyone have any clue why this freezes when there are no files? I must be blind because I can't figure it out!!!

Thanks for any help!