Page 1 of 1

Get last Error / ErrorCode

Posted: Thu 04 Dec 2014 13:54
by kaju74
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

Re: Get last Error / ErrorCode

Posted: Tue 09 Dec 2014 08:40
by Dimon
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.

Re: Get last Error / ErrorCode

Posted: Wed 10 Dec 2014 10:05
by kaju74
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

Re: Get last Error / ErrorCode

Posted: Fri 12 Dec 2014 17:17
by Dimon
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.

Re: Get last Error / ErrorCode

Posted: Mon 15 Dec 2014 10:42
by kaju74
Hi.

Thank you - that would be great.

Regards & marry x-mas,
Marc

Re: Get last Error / ErrorCode

Posted: Thu 12 Feb 2015 15:00
by ViktorV
The new SecureBridge build including the EScError.ErrorCode property is available for download now.