Connection error block our application


we are using smartFTP library with success. We only have a small problem when the following error occurs during connection (very few times):
[20051220 03:31:19] SmartFTP FTP Library v1.5.6.0
[20051220 03:31:19] Resolving host name "****"
[20051220 03:31:19] Connecting to ***** Port: ***
[20051220 03:31:20] No connection could be made because the target machine actively refused it.
[20051220 03:31:20] Client closed the connection.
[20051220 03:27:23] SmartFTP FTP Library v1.5.6.0
[20051220 03:27:23] Resolving host name "****"
[20051220 03:27:23] Connecting to ***** Port: ***
[20051220 03:27:23] Connected to *****
[20051220 03:27:23] Server closed connection

In these cases, our application using smartFTP is blocked. It doesn't continue the process. We can not be advertised that the application is blocked.

These error happens very few time with our FTP Server (ProFTPd). So, the connection error can occur but our application should handle these cases and continue the process with a log message.

In our code, we check the return value of the connect() function :
IF FTPC.Connect()<>0 THEN

We also regulary check the connection status :
gf_CheckStatus() retboo : Boolean
IF (gboo_Error) THEN
IF (FTPC.ConnectionStatus<>2) THEN

We also check the event OnStatus :
FTPC::OnStatus(t : Integer;szText : Text[1024])
ltex1024_StatusText := '';
CASE szText OF
'1':ltex1024_StatusText := szText + ' : Unable to resolve host name.';
'2':ltex1024_StatusText := szText + ' : Connection to host failed.';
'3':ltex1024_StatusText := szText + ' : Timeout.';
ELSE ltex1024_StatusText := 'Unknown Local Error';
4:ltex1024_StatusText := szText;
ELSE ltex1024_StatusText := '';
IF (ltex1024_StatusText <> '') THEN
FORMAT(t),COPYSTR(ltex1024_StatusText, 1, 50),'','','',FALSE);

Have you an idea of why our application is blocked in case of connection errors ?

Thanks in advance for your feedback,

Hello ..

What FTPConnection class do you use? MTA or STA?

What language do you use? Delphi? What version?



We use the STA class and we are working in the developement environment of Navision Attain 360 (ERP).
MTA class is not applicable for us (see my other resquest).

In the case of the first error ("No connection could be made ..."), what is the return value of the connect() function ? Is the event OnStatus fired ? What are the values of the parameters in this case ?

In the case of the second error ("Server closed connection..."), what is the return value of the connect() function ? Is the event OnStatus fired ? What are the values of the parameters in this case ?

SmartFTP is waiting for something special from the FTP server or the application in these cases ? The more important thing to do, is to understand why the application is blocked.

Thanks in advance,

Hello ..

I think you have a dead lock.

1. If the connection attempt fails the Connect() function will return with an error.

enum enumError {
ftpErrorSuccess = 0L,
ftpErrorUnknown = 1L,
ftpErrorBusy = 2L,
ftpErrorNotConnected = 3L,
ftpErrorTimeout = 4L,
ftpErrorBadArguments = 5L,
ftpErrorOutOfMemory = 6L,
ftpErrorNotImplemented = 7L,
ftpErrorNoOperation = 8L,
ftpErrorPending = 9L,
ftpErrorInternal = 10L,
ftpErrorResolveHost = 11L,
ftpErrorSocket = 12L,
ftpErrorNotInit = 13L,
ftpErrorAborted = 14L,
ftpErrorWrongReply = 15L,
ftpErrorNotClosed = 16L,
ftpErrorLicense = 17L,
ftpErrorSSL = 18L,
ftpErrorMoreData = 19L,
ftpErrorPaused = 20L,
ftpErrorSettingMismatch = 21L,
ftpErrorNotDisconnected = 22L,
ftpErrorConnectionClosed = 23L

2. Events should be used for information purpose only. Do not call any further functions from the FTPConnection object in the events. Reading/writing object properties are fine.
Also do not check for any errors in the OnStatus event. Errors are returned by every function. See 1.

3. There is not really a need to check constantly for the status of the connection:
IF (FTPC.ConnectionStatus<>2) THEN
If the connection gets closed the functions will return an error (See 1).

Regarding the dead lock. Try to remove the OnStatus event and any other events you may have. See if this solves the problem. Avoid any event processing if possible.

I hope this helps.