FTP - Problem, always prompt timeout or connection timeout
Hi guys, I always got a connection timeout or timeout error while doing my ftp transfer. If i get 10 files from server most of the time the 1st item is the only one that is successful the remaining will timeout or worst case all of them will timeout. Here is my code.
Re: FTP - Problem, always prompt timeout or connection timeout
Code:
Public sub GetFTP()
On Error GoTo ImportErr
Dim host_name As String
Dim fso As New FileSystemObject
iTotal = 0
iSent = 0
grdFiles.RemoveAll
Screen.ActiveForm.Enabled = False
Screen.MousePointer = vbHourglass
txtResults.Text = ""
host_name = gstIP
If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name
inetFTP.URL = host_name
With inetFTP
.Execute , "CD " & sFTPFolder & "/Export"
Call pWaitForResponse
.Execute , "Dir"
Call pWaitForResponse
vChunk = .GetChunk(1024, icString)
Call pWaitForResponse
Do Until bDone
sDirectory = sDirectory & vChunk
vChunk = .GetChunk(1024)
If Len(vChunk) = 0 Then bDone = True
Loop
End With
Dim i As Integer
Dim sFTPFile As String
Dim sMatchStr As String
sMatchStr = UCase$(".exp")
Do Until Len(sDirectory) = 0
i = InStr(1, sDirectory, Chr$(13))
If i > 0 Then
If Len(sDirectory) <= 2 Then
sDirectory = ""
Exit Do
End If
sFTPFile = UCase$(Left$(sDirectory, i - 1))
If InStr(1, sFTPFile, sMatchStr) > 0 Then
grdFiles.AddItem "0" & vbTab & sFTPFile
End If
sDirectory = Mid$(sDirectory, i + 2)
End If
Loop
iSent = 1
iTotal = grdFiles.Rows
If grdFiles.Rows > 0 Then
prgStatus.Visible = True
prgStatus.Value = iSent
prgStatus.Max = iTotal
lblStatus.Caption = "Still Executing, Please wait!.. Recieving " & iSent & " of " & iTotal & " files.."
DoEvents
Do Until iSent - 1 > iTotal
stFile = grdFiles.Columns("filename").Value
If Not CBool(grdFiles.Columns("check").Value) Then
If inetFTP.StillExecuting Then
inetFTP.Cancel
pWaitForResponse
End If
If fso.FileExists(gstImport & "\" & stFile) Then Call fso.DeleteFile(gstImport & "\" & stFile, True)
AddMessage "Importing " & stFile
inetFTP.Execute , "Get " & _
"/Export/" & stFile & " " & gstImport & "\" & stFile
pWaitForResponse
End If
If boSent Then 'Return true if Succesufully Sent
Dim lFile As String
Dim rFile As String
lFile = GetFTPFileSize("/Export/" & stFile)
rFile = FileLen(gstImport & "\" & stFile)
If lFile = rFile Then
AddMessage "Deleting " & stftpfile
inetFTP.Execute , "Delete " & "/Export/" & stFile
Call pWaitForResponse
DoEvents
iSent = iSent + 1
grdFiles.Columns("check").Value = True
grdFiles.MoveNext
prgStatus.Value = iSent
lblStatus.Caption = "Still Executing, Please wait!.. Recieving " & iSent & " of " & iTotal & " files.."
End If
End If
Loop
End If
If iSent = iTotal Then
lblStatus.Caption = "Transfer successfully done.."
prgStatus.Value = 0
MsgBox iSent & " out of " & iTotal & " succesfully received!...", vbInformation
Else
lblStatus.Caption = "Transfer partially done.. Please try again.."
prgStatus.Value = 0
MsgBox iSent & " out of " & iTotal & " succesfully received!.. Please try again..", vbInformation
End If
Screen.ActiveForm.Enabled = True
Screen.MousePointer = vbDefault
Exit Sub
ImportErr:
MsgBox Err.Description & vbCrLf & "Please try again..", vbCritical
inetFTP.Cancel
Screen.ActiveForm.Enabled = True
Screen.MousePointer = vbDefault
End Sub
Private Sub pWaitForResponse()
Dim i As Integer
'
' This loop waits until an FTP action completes.
'
Do Until Not inetFTP.StillExecuting
DoEvents
Sleep (100)
If inetFTP.ResponseInfo = "Timeout" Then
AddMessage inetFTP.ResponseInfo
boSent = False
Exit Do
End If
Loop
Re: FTP - Problem, always prompt timeout or connection timeout
personally, i would not be using inet control to do ftp, but it should work, i have tested before
no one can really test for you as any problem can be server specific, and we can not see the content of your variables for possible problems, it looks to me as if you maybe trying to download the complete content of a folder, but i am not sure on that, on many servers filenames are case sensitive, which may cause problems
Quote:
vChunk = .GetChunk(1024, icString)
what is the value of icstring
Re: FTP - Problem, always prompt timeout or connection timeout
what i am thinking is it might be an network problem. sometimes my data transfer is good, but most of the time in result to a timeout.
Re: FTP - Problem, always prompt timeout or connection timeout
Quote:
what i am thinking is it might be an network problem
you can not control networks
try doing the same downloads with a ftp client, i use fireftp, but there are many to choose from, see if it has the same problems
or you can pm me with details for your ftp server and i will give it a test later
Re: FTP - Problem, always prompt timeout or connection timeout
i try to ping the server and i notice every time i got a timeout response the file on transferring status will result to connection timeout.