FTP on unstable connection

Giganews Newsgroups
Subject: FTP on unstable connection
Posted by:  Christian Kaufmann (christian.kaufma…@gmx.net)
Date: Wed, 30 Mar 2011

Hi,

in my application I have a background thread, which uploads files to a
server. Basically it works fine, but some users report problems. I
think it has to do with their connection to the internet (wireless,
many users) which causes timeouts and aborts.

I would like to correct my code that way, that the thread does not
fail, but just tries again when it is executed for the next time.

Can somebody give me a hint, what I should change in my code?

Thanks

cu Christian

-----

The code in my execute methode is something like this:

      EnsureUploadFile('file1');
      EnsureUploadFile('file2');
      EnsureUploadFile('file3');

      if FFtpClient.Connected
        then FFtpClient.Disconnect;

procedure TLiveResult.EnsureUploadFile(const AFile: String);
var
  err : String;
  tmp : String;
begin
  if [ AFile doesn't need upload ]
    then Exit;

    if not FFtpClient.Connected then begin
      FFtpClient.Connect;
      FFtpClient.RemoteChangeDir(FRemoteDirectory);
    end;
    FFtpClient.Put(AFile, AFile, False);
  end;
end;

From the users I get all kind of different exceptions. Here are some,
logged with madExcept, only the stack trace for my FTP thread. The
exception itself is always reported as "unknown".

thread $16cc (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
76f69b66 ntdll.dll                          RtlRaiseStatus
76f699f2 ntdll.dll                          KiUserExceptionDispatcher
005a8e4e Meet11.exe  IdStack          660
TIdStack.RaiseLastSocketError
005a8db9 Meet11.exe  IdStack          634
TIdStack.CheckForSocketError
005a7f75 Meet11.exe  IdStackBSDBase    409 TIdStackBSDBase.Receive
0068f4f2 Meet11.exe  IdSocketHandle    313 TIdSocketHandle.Receive
0069146a Meet11.exe  IdIOHandlerStack  372
TIdIOHandlerStack.ReadDataFromSource
0068dbc9 Meet11.exe  IdIOHandler      1471
TIdIOHandler.ReadFromSource
0069104b Meet11.exe  IdIOHandlerStack  231
TIdIOHandlerStack.Connected
00690608 Meet11.exe  IdTCPConnection  495 TIdTCPConnection.Connected
00a42d39 Meet11.exe  BSFtp            104 TBSFtpClient.Connected
00a78de7 Meet11.exe  liveResult        710 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System            163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
76ad490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($14a0) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $16cc (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
76f69b66 ntdll.dll                          RtlRaiseStatus
76f699f2 ntdll.dll                          KiUserExceptionDispatcher
005a8e4e Meet11.exe  IdStack          660
TIdStack.RaiseLastSocketError
005a8db9 Meet11.exe  IdStack          634
TIdStack.CheckForSocketError
005a7f75 Meet11.exe  IdStackBSDBase    409 TIdStackBSDBase.Receive
0068f4f2 Meet11.exe  IdSocketHandle    313 TIdSocketHandle.Receive
0069146a Meet11.exe  IdIOHandlerStack  372
TIdIOHandlerStack.ReadDataFromSource
0068dbc9 Meet11.exe  IdIOHandler      1471
TIdIOHandler.ReadFromSource
0069104b Meet11.exe  IdIOHandlerStack  231
TIdIOHandlerStack.Connected
00690608 Meet11.exe  IdTCPConnection  495 TIdTCPConnection.Connected
00a42d39 Meet11.exe  BSFtp            104 TBSFtpClient.Connected
00a78de7 Meet11.exe  liveResult        710 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System            163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
76ad490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($14a0) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $e8c (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
76f69b66 ntdll.dll                        RtlRaiseStatus
76f699f2 ntdll.dll                        KiUserExceptionDispatcher
0040655a Meet11.exe  System          163 @HandleFinallyInternal
76f69b66 ntdll.dll                        RtlRaiseStatus
76f4d371 ntdll.dll                        RtlUnwind
0040642e Meet11.exe  System          163 @HandleOnException
76f69b66 ntdll.dll                        RtlRaiseStatus
76f699f2 ntdll.dll                        KiUserExceptionDispatcher
0069073f Meet11.exe  IdTCPConnection  564
TIdTCPConnection.GetResponse
00a3eb0f Meet11.exe  IdFTP          1550
TIdFTP.FinalizeDataOperation
00a3f0a1 Meet11.exe  IdFTP          1677 TIdFTP.InternalPut
00a3f4ff Meet11.exe  IdFTP          1930 TIdFTP.Put
00a3f5d4 Meet11.exe  IdFTP          1946 TIdFTP.Put
00a42f63 Meet11.exe  BSFtp            233 TBSFtpClient.Upload
00a799dc Meet11.exe  liveResult      813
TLiveResult.EnsureUploadFile
00a77e27 Meet11.exe  liveResult      456 TLiveResult.CheckLastHeat
00a785e2 Meet11.exe  liveResult      586 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System          163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
76ad490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($1488) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $16d0 (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
7c91e485 ntdll.dll                        KiUserExceptionDispatcher
7c801a7f kernel32.dll                      VirtualProtectEx
7c801ae7 kernel32.dll                      VirtualProtect
0068f033 Meet11.exe  IdIOHandler    2384 TIdIOHandler.WriteDirect
0068edf2 Meet11.exe  IdIOHandler    2264 TIdIOHandler.Write
0068d1c5 Meet11.exe  IdIOHandler      962 TIdIOHandler.Write
0068e108 Meet11.exe  IdIOHandler    1646 TIdIOHandler.WriteLn
00a3f12e Meet11.exe  IdFTP          1827 TIdFTP.DisconnectNotifyPeer
00a42e12 Meet11.exe  BSFtp            126 TBSFtpClient.Disconnect
7c91e485 ntdll.dll                        KiUserExceptionDispatcher
7c801a7f kernel32.dll                      VirtualProtectEx
7c801ae7 kernel32.dll                      VirtualProtect
0068f033 Meet11.exe  IdIOHandler    2384 TIdIOHandler.WriteDirect
0068edf2 Meet11.exe  IdIOHandler    2264 TIdIOHandler.Write
0068d1c5 Meet11.exe  IdIOHandler      962 TIdIOHandler.Write
0068e108 Meet11.exe  IdIOHandler    1646 TIdIOHandler.WriteLn
00a3f12e Meet11.exe  IdFTP          1827 TIdFTP.DisconnectNotifyPeer
006906ae Meet11.exe  IdTCPConnection  519 TIdTCPConnection.Disconnect
00690dbc Meet11.exe  IdTCPConnection  857 TIdTCPConnection.Disconnect
00a42df6 Meet11.exe  BSFtp            124 TBSFtpClient.Disconnect
00a78df9 Meet11.exe  liveResult      711 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System          163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
>> created by main thread ($9c4) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $a14 (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
76f69b66 ntdll.dll                          RtlRaiseStatus
76f699f2 ntdll.dll                          KiUserExceptionDispatcher
005a8e4e Meet11.exe  IdStack          660
TIdStack.RaiseLastSocketError
005a8db9 Meet11.exe  IdStack          634
TIdStack.CheckForSocketError
005a7f75 Meet11.exe  IdStackBSDBase    409 TIdStackBSDBase.Receive
0068f4f2 Meet11.exe  IdSocketHandle    313 TIdSocketHandle.Receive
0069146a Meet11.exe  IdIOHandlerStack  372
TIdIOHandlerStack.ReadDataFromSource
0068dbc9 Meet11.exe  IdIOHandler      1471
TIdIOHandler.ReadFromSource
0069104b Meet11.exe  IdIOHandlerStack  231
TIdIOHandlerStack.Connected
00690608 Meet11.exe  IdTCPConnection  495 TIdTCPConnection.Connected
00a42d39 Meet11.exe  BSFtp            104 TBSFtpClient.Connected
00a799a6 Meet11.exe  liveResult        809
TLiveResult.EnsureUploadFile
00a79ac9 Meet11.exe  liveResult        822
TLiveResult.EnsureUploadFiles
00a78b25 Meet11.exe  liveResult        678 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System            163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
76ad490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($3c4) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $900 (TLiveResult):
005e330a Meet11.exe  BSTypes          500 TBSThread.Execute
76f69b66 ntdll.dll                        RtlRaiseStatus
76f699f2 ntdll.dll                        KiUserExceptionDispatcher
0040655a Meet11.exe  System          163 @HandleFinallyInternal
76f69b66 ntdll.dll                        RtlRaiseStatus
76f4d371 ntdll.dll                        RtlUnwind
0040642e Meet11.exe  System          163 @HandleOnException
00740070 Meet11.exe  BSLanguageBO    790 TBSLanguageFile.SaveToFile
76f69b66 ntdll.dll                        RtlRaiseStatus
76f699f2 ntdll.dll                        KiUserExceptionDispatcher
0069073f Meet11.exe  IdTCPConnection  564
TIdTCPConnection.GetResponse
00a3eb0f Meet11.exe  IdFTP          1550
TIdFTP.FinalizeDataOperation
00a3f0a1 Meet11.exe  IdFTP          1677 TIdFTP.InternalPut
00a3f4ff Meet11.exe  IdFTP          1930 TIdFTP.Put
00a3f5d4 Meet11.exe  IdFTP          1946 TIdFTP.Put
00a42f63 Meet11.exe  BSFtp            233 TBSFtpClient.Upload
00a799dc Meet11.exe  liveResult      813
TLiveResult.EnsureUploadFile
00a79ac9 Meet11.exe  liveResult      822
TLiveResult.EnsureUploadFiles
00a78b25 Meet11.exe  liveResult      678 TLiveResult.DoExecute
005e32a1 Meet11.exe  BSTypes          488 TBSThread.Execute
004594e3 Meet11.exe  madExcept            HookedTThreadExecute
0049b9f6 Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System          163 ThreadWrapper
004593c5 Meet11.exe  madExcept            CallThreadProcSafe
0045942f Meet11.exe  madExcept            ThreadExceptFrame
76ad490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($1690) at:
005e311a Meet11.exe  BSTypes          427 TBSThread.Create

thread $12b0 (TLiveResult):
005e10ae Meet11.exe  BSTypes          498 TBSThread.Execute
77729b66 ntdll.dll                          RtlRaiseStatus
777299f2 ntdll.dll                          KiUserExceptionDispatcher
005a87e2 Meet11.exe  IdStack          660
TIdStack.RaiseLastSocketError
005a874d Meet11.exe  IdStack          634
TIdStack.CheckForSocketError
005a7909 Meet11.exe  IdStackBSDBase    409 TIdStackBSDBase.Receive
0068d106 Meet11.exe  IdSocketHandle    313 TIdSocketHandle.Receive
0068f07e Meet11.exe  IdIOHandlerStack  372
TIdIOHandlerStack.ReadDataFromSource
0068b7dd Meet11.exe  IdIOHandler      1471
TIdIOHandler.ReadFromSource
0068ec5f Meet11.exe  IdIOHandlerStack  231
TIdIOHandlerStack.Connected
0068e21c Meet11.exe  IdTCPConnection  495 TIdTCPConnection.Connected
00a3a589 Meet11.exe  BSFtp            103 TBSFtpClient.Connected
00a711ee Meet11.exe  liveResult        809
TLiveResult.EnsureUploadFile
00a71337 Meet11.exe  liveResult        823
TLiveResult.EnsureUploadFiles
00a7036d Meet11.exe  liveResult        678 TLiveResult.DoExecute
005e1045 Meet11.exe  BSTypes          486 TBSThread.Execute
00458e77 Meet11.exe  madExcept            HookedTThreadExecute
0049b38a Meet11.exe  Classes              ThreadProc
00406d84 Meet11.exe  System            140 ThreadWrapper
00458d59 Meet11.exe  madExcept            CallThreadProcSafe
00458dc3 Meet11.exe  madExcept            ThreadExceptFrame
7652490f kernel32.dll                      BaseThreadInitThunk
>> created by main thread ($f74) at:
005e0ebe Meet11.exe  BSTypes          425 TBSThread.Create

Replies