EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSHClient Sample -- internally trap auth. error dialog

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
Posted: 05/17/2006 14:23:58
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

Indeed, your suggestion took care of one of the exceptions thrown in the IDE. However, even outside of the IDE, using a "release build", I'm still getting: modal display of dialog box with title bar "Sshdemo", message text = "SSH connection failed due to error (114)", and a single "OK"-button, i.e. to discharge the dialog...
I need to handle connections, via SSH, to hundreds of Unix/Linux servers, etc., programmatically and unattended. A modal dialogbox coming up when a particular user i.d./password combination is incorrect for a server, is not going to be acceptable. Can you recommend where to stick a try..catch construct to catch this exception, i.e. before it throws the dialogbox ?
Posted: 05/17/2006 14:44:21
by Eugene Mayevski (EldoS Corp.)

There's one place where the dialog box is shown -- in SSHDemo.cpp there's a try/catch block which displays exception text. Of course you can move this try/catch to Button1Click() in MainForm.cpp, around a call to Open() method.

Sincerely yours
Eugene Mayevski
Posted: 05/17/2006 14:58:41
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

This seemed to do the trick :

void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
Memo2->Lines->Add("Client socket connected");
try {
} catch (...) {
if (Client->Active)
Memo2->Lines->Add("Connection started");
Memo2->Lines->Add(AnsiString("Server: ") + Client->ServerSoftwareName);
switch (Client->Version)
case sbSSH1 :
Memo2->Lines->Add("Version: SSHv1");
case sbSSH2 :
Memo2->Lines->Add("Version: SSHv2");
Posted: 05/17/2006 15:00:58
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

Putting the try...catch into Button1Click didn't seem to do it, i.e. uncommenting it in this code :
void __fastcall TForm1::Button1Click(TObject *Sender)
TElSSHKey* Key;

if (!Connected){
Sbsshcommon::TSSHVersions versions;
if (CheckBox1->Checked)
versions << sbSSH1;
if (CheckBox2->Checked)
versions << sbSSH2;
Client->Versions = versions;
Client->Username = Edit3->Text;
Client->Password = Edit4->Text;

Key = new TElSSHKey();
if ((Edit6->Text.Length() != 0) && (Key->LoadPrivateKey(Edit6->Text, "") == 0))
Client->AuthenticationTypes = Client->AuthenticationTypes | SSH_AUTH_TYPE_PUBLICKEY;
Client->AuthenticationTypes = Client->AuthenticationTypes & (~SSH_AUTH_TYPE_PUBLICKEY);

Client->AuthenticationTypes = Client->AuthenticationTypes | (SSH_AUTH_TYPE_PASSWORD);
Client->AuthenticationTypes = Client->AuthenticationTypes | (SSH_AUTH_TYPE_KEYBOARD);

delete Key;

ClientSocket1->Host = Edit1->Text;
ClientSocket1->Port = atoi((const char *) Edit2->Text.c_str());
//try {
Button1->Caption = "Disconnect";
Connected = true;
//} catch (...) {
} else {
if (Client->Active)
Button1->Caption = "Connect";
Connected = false;



Topic viewed 14991 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!