Get last Error / ErrorCode

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
kaju74
Posts: 3
Joined: Thu 04 Dec 2014 13:49

Get last Error / ErrorCode

Post by kaju74 » Thu 04 Dec 2014 13:54

Hi.

I'm new to this product and have a tiny problem here. Connected a SFTP component with a SSH client. For testing purposes, I've disabled SSH support on my ftp server. As soon as I try to connect to that server, I've got an error message:

"Server does not support SFTP protocol"

That's fine, but why does the OnError event from the SFTP-component isn't triggered?

Then, I've tryed to catch all errors inside a "Try/Except" block -> works. But how do I get the last error-code from the ftp/ssh-client to be able to translate this codes to my own messages (german)?

Regards,
Marc

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Get last Error / ErrorCode

Post by Dimon » Tue 09 Dec 2014 08:40

The OnError event occurs when the SFTP server returns an error on executing some operation with files.
In your case SSH server just closes the connection and doesn't return any code error, therefore the OnError event is not raised.
To solve the problem you can process the TScSFTPClient.OnDisconnect event handler and display your own message.

kaju74
Posts: 3
Joined: Thu 04 Dec 2014 13:49

Re: Get last Error / ErrorCode

Post by kaju74 » Wed 10 Dec 2014 10:05

Hi,

hmm...OnDisconnect doesn't return any messaage to be able to translate. I need german error messages instead of english ones, so it would be cool to be able to retrieve the last occured error in a further release.

For now, I've a "CheckFTPConnection" procedure where the statement "SSHClient.Connect" is surrounded by a try-except block and the following code:

Code: Select all

  try
    ...
  except
    { catch all errors }
    on e: Exception do
    begin
      { close ssh connection }
      SSHClient.Disconnect;

      { set result }
      Result := False;

      { translate message? }
      AMessage := e.Message;
      if TNXStrings.Search('SFTP protocol', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_PROTOCOL;
      if TNXStrings.Search('Host key not', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_HOSTKEY;
      if TNXStrings.Search('Wrong host', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_HOSTNAME;
      if TNXStrings.Search('Socket error', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_SOCKET;
      if TNXStrings.Search('Authentication', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_AUTHENTICATION;
      if TNXStrings.Search('Timeout', AMessage, True) > 0 then
        AMessage := S_SSH_ERROR_TIMEOUT;

      { show error message }
      xpExclamMessageFmt(S_FTP_CONNECTION_ERROR, [AMessage]);
    end;
Using a string parser isn't the best methode here, cause I don't know, which other errors could occur, too.

Regards,
Marc

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Get last Error / ErrorCode

Post by Dimon » Fri 12 Dec 2014 17:17

Thank you for your inquiry. We will investigate the possibility of adding this functionality in the future. As soon as we solve this question we will let you know.

kaju74
Posts: 3
Joined: Thu 04 Dec 2014 13:49

Re: Get last Error / ErrorCode

Post by kaju74 » Mon 15 Dec 2014 10:42

Hi.

Thank you - that would be great.

Regards & marry x-mas,
Marc

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Get last Error / ErrorCode

Post by ViktorV » Thu 12 Feb 2015 15:00

The new SecureBridge build including the EScError.ErrorCode property is available for download now.

Post Reply