EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to use custom file encoding from TElSimpleSFTPClient?

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
Posted: 06/02/2016 00:44:18
by hiesto (Basic support level)
Joined: 05/25/2016
Posts: 7

Hello, I'm working on SecureBlackBox for JAVA version.

This is part of run script from my project.

java -Djava.class.path="%JPATH%" -Duser.language=en -Duser.country=US
-DD2_JS_HOME="%HOME%" -DSERVER_TYPE="SERVER" -Dfile.encoding=MS949 -Xms128M -Xmx512M ...

You can see the option "-Dfile.encoding=MS949".

First of all, there is no problems in TElSimpleFTPSClient with this option.

But, I can't connect to SFTP server to using TElSimpleSFTPClient with custom file encoding option.

Also, If I use this options, SFTP Demo project is not working too.

Anyway, If I change system property of file.encoding to UTF-8, It can be connect to SFTP server.

ex ) System.setProperty("file.encoding", "UTF-8");

But, I can't change system property in my project because of this problem.

I want to know, how to use custom system property of file.encoding in TElSimpleSFTPClient.


P.S here is exception log.

SecureBlackbox.SFTPClient.EElSimpleSFTPClientError: Connection lost (error code is 10058)
at SecureBlackbox.SFTPClient.TElSimpleSFTPClient.doSend(SBSimpleSftp.pas:1765)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.freepascal.rtl.FpcBaseProcVarType.invokeObjectFunc(system.pp)
at SecureBlackbox.SSHCommon.TSSHSendEvent.invoke(SBSSHCommon.pas)
at SecureBlackbox.SSHCommon.TElSSHClass.doSend(SBSSHCommon.pas:2614)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2SendOnTransportLayer(SBSSHClient.pas:11729)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2SendDisconnect(SBSSHClient.pas:11775)
at SecureBlackbox.SSHClient.TElSSHClient.performClose(SBSSHClient.pas:17816)
at SecureBlackbox.SSHClient.TElSSHClient.closeByError(SBSSHClient.pas:1406)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ContinueAuthentication(SBSSHClient.pas:9739)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ParseServerUserauthFailure(SBSSHClient.pas:9537)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2EstablishAuthPublicKey(SBSSHClient.pas:14083)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ContinueAuthentication(SBSSHClient.pas:9683)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ParseServerUserauthFailure(SBSSHClient.pas:9537)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ParseOnUserauthLayer(SBSSHClient.pas:5539)
at SecureBlackbox.SSHClient.TElSSHClient.ssh2ParseOnTransportLayer(SBSSHClient.pas:5471)
at SecureBlackbox.SSHClient.TElSSHClient.analyseBuffer(SBSSHClient.pas:1804)
at SecureBlackbox.SSHClient.TElSSHClient.dataAvailable(SBSSHClient.pas:1467)
at SecureBlackbox.SFTPClient.TElSimpleSFTPClient.dataAvailable(SBSimpleSftp.pas:1566)
at SecureBlackbox.SFTPClient.TElSimpleSFTPClient.intMessageLoop(SBSimpleSftp.pas:6199)
at SecureBlackbox.SFTPClient.TElSimpleSFTPClient.doMessageLoop(SBSimpleSftp.pas:1683)
at SecureBlackbox.SFTPClient.TElSimpleSFTPClient.open(SBSimpleSftp.pas:5024)
at ManagerSBBoxSFTP2.<init>(SBBoxSFTP.java:109)
at test.<init>(test.java:37)
at test.main(test.java:206)

and this is demo project error log


msg : Connecting to
msg : Server key [e4dd112e8234ab62591cc8621d4b4899] received
msg : Authentication type [2] failed
msg : Error 114
msg : Connection failed due to exception: Connection lost (error code is 10058)
msg : If you have ensured that all connection parameters are correct and you still can't connect,
msg : please contact EldoS support as described on http://www.eldos.com/sbb/support-tech.php
msg : Remember to provide details about the error that happened.
msg : Server software identified itself as: Serv-U_15.1.3.3
Posted: 06/02/2016 02:45:48
by Eugene Mayevski (EldoS Corp.)

The log says that your authentication with a public key fails.

It is likely, that with non-UTF charset your key is not properly loaded. Please inspect the value, that loadPrivateKey() method returns. It can be non-zero in case when the charset is not UTF.

Sincerely yours
Eugene Mayevski
Posted: 06/02/2016 03:22:35
by hiesto (Basic support level)
Joined: 05/25/2016
Posts: 7

In my case, TElSSHKey.loadPrivateKey() method is always returns zero.
Below is kind of your SFTP Demo project.
if (dlg.getPrivateKey().compareTo("") != 0)
   int err = Key.loadPrivateKey(dlg.getPrivateKey(), dlg.getPrivateKeyPassword());
   if (err == 0)
      ftp.setAuthenticationTypes(ftp.getAuthenticationTypes() | SBSSHConstants.SSH_AUTH_TYPE_PUBLICKEY);
      ftp.setAuthenticationTypes(ftp.getAuthenticationTypes() &
      log("Private key file could not be loaded due to error "  + err, true);

Demo project are make error log when loadPrivateKey() returns non-zero.
Pls, check the demo project error log above.

Also, I trying another loadPrivateKey() method like this.
File file = new File(getKeyPath());         
byte[] keyData = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
int err = Key.loadPrivateKey(keyData, keyData.length, getKeyPasswd());

It returns zero. But still I can't connect to SFTP server because same reasion.
I don't think this is an authentication problem.

At last, here is protection code in my source.
System.setProperty("file.encoding", "UTF-8");
System.setProperty("file.encoding", "MS949");

If I change system property of file.encoding before open() method, then It can be connect to server.
But, I don't want to change system property for this problems.

Please, tell me how to using custom file.encoding.
Posted: 06/02/2016 04:55:57
by Eugene Mayevski (EldoS Corp.)

Thank you very much for the clarification and tests. The only other idea that comes to my mind is that you have non-latin characters in the username. There's no other place for the encoding to affect login sequence.

Sincerely yours
Eugene Mayevski
Posted: 06/03/2016 00:28:54
by hiesto (Basic support level)
Joined: 05/25/2016
Posts: 7

Here is my full test code.
Please, Check it out.
ftp = new TElSimpleSFTPClient();


keyStorage = new TElSSHMemoryKeyStorage();


TElSSHKey Key = new TElSSHKey();
ftp.setAuthenticationTypes(SBSSHConstants.SSH_AUTH_TYPE_PASSWORD | SBSSHConstants.SSH_AUTH_TYPE_KEYBOARD);

   int err = Key.loadPrivateKey("D:\\test_SFTP\\key\\sftp\\private.ppk", "4231");
   if (err == 0)
      ftp.setAuthenticationTypes(ftp.getAuthenticationTypes() | SBSSHConstants.SSH_AUTH_TYPE_PUBLICKEY);
      ftp.setAuthenticationTypes(ftp.getAuthenticationTypes() & (~SBSSHConstants.SSH_AUTH_TYPE_PUBLICKEY));
      log("Private key file could not be loaded due to error "  + err, true);
catch (Exception e)

For your information, Filezilla ftp client is working normally for all same conditions.

And once again, TElSimpleFTPSClient is working normally.
It means there is some changes between TElSimpleSFTPClient and TElSimpleFTPSClient.

If there is no other options, I thinks this problem is caused by TElSimpleSFTPClient bug.

Could you fix it?
Posted: 06/03/2016 04:17:47
by Vsevolod Ievgiienko (EldoS Corp.)


Could you please add next code before connection is opened and check if there is some output to the console:

SBUtils.setDefaultExceptionHandler(new TElCustomExceptionHandler() {
         public boolean handleException(Exception ex) {
            return false;

It will dump all internal exceptions if they happen. Its possible that some encoding/decoding function fails internaly.
Posted: 06/06/2016 22:06:20
by hiesto (Basic support level)
Joined: 05/25/2016
Posts: 7

Sorry for late answer.

Added below codes before the create TElSimpleSFTPClient object.
But, there is no output to console when connect to server.

Anyway if I using debugging run from Eclipse.
Breakpoint has occurred by TEISSHClient.dataAvailable() method.

Please check attached image.

Posted: 06/07/2016 02:34:44
by Eugene Mayevski (EldoS Corp.)

Thank you for the additional details. Unfortunately it doesn't shed more light on the problem - the call stacks (both previous and the new one) are about disconnection itself, and don't expose the issues with strings. I am sorry to say this, but it looks like we are not able to solve the issue without reproducing it. It is possible, that the issue is specific to the combination of your environment, particular server and user name.

Sincerely yours
Eugene Mayevski
Posted: 06/07/2016 04:33:28
by hiesto (Basic support level)
Joined: 05/25/2016
Posts: 7

Thanks for quick answer.

And as a result, I decided to use my protection code.
That's all.

Finally, another in my test code.
There is some other error if I use next code.


There is no file encoding option like "UTF".

But I don't use system property option when connect ftp server.
So, it should be no errors in my test.

But, It is always occurred error in SFTPClient.open() method.
Just try add this code before connection.
There is some part of using system.property of file.encoding options when connect to server.

Anyway, thanks for your helps.
Best regards.
Posted: 06/08/2016 08:43:56
by Vsevolod Ievgiienko (EldoS Corp.)


I've created a Helpdesk ticket for you and posted a custom test build there. Please check if it works without your workaround.
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.



Topic viewed 991 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!