We have been trying to figure out a connection problem for awhile and think we discovered a bug.
First, we have studied the SSHClient demo extensively and tested it with our test SSHServer and it works. We can connect to our test server. We can also connect using putty and our previous SSHClient.
However, we can not connect when we create a sub class of the TScSSHClient object in the following code.
We have subclasses for all our connections in our Delphi application, such as our previous SSHClient object, an FTP object, a Telnet object, a TCIPClient object and a TCPIPServer object. So we know how to create them.
Please look at the procedure SClientBeforeConnect. In there we can see that the host, port, username and password all match.
We are not sure who it is trying to connect to when we call ssclint[whport].Connect in the Connect_Client function. We have also checked the hostname, port number, username and password before we call ssclint[whport].Connect and they all match just like they match in the SClientBeforeConnect.
Please help...
Code: Select all
Const
maxrecords=10;
type
tsshcclient=class(TScSSHClient)
public
devs:integer;
port:integer;
procedure SClientBeforeConnect(Sender: TObject);
procedure SClientAfterConnect(Sender: TObject);
procedure SClientAfterDisconnect(Sender: TObject);
procedure SClientKeyValidation(Sender:tobject; Newserverkey:TSckey; var Accept:boolean);
end;
var
ssclint:array [0..maxrecords] of tsshcclient;
ssfiles:TScFileStorage;
function createssclient(whport:integer):integer;
var crteans:integer; ipstr:string;
begin
with portvars^ do
begin
ipstr:=ipprt;
delete(ipstr,1,6);
if ssfiles=nil then ssfiles:=TScFileStorage.create(nil);
if ssfiles<>nil then
begin
ssfiles.Path:=wavepath;
ssclint[whport]:=tsshcclient.Create(nil);
if ssclint[whport]<>nil then
begin
crteans:=0;
ssclint[whport].KeyStorage:=ssfiles;
ssclint[whport].HostKeyAlgorithms.AsString:='ssh-rsa,ssh-dss';
ssclint[whport].Authentication:=atpassword;
ssclint[whport].HostName:=get_str_item(ipstr,1,';');
ssclint[whport].Port:=strtoint(get_str_item(ipstr,2,';'));
ssclint[whport].User:=get_str_item(ipstr,3,';');
ssclint[whport].Password:=get_str_item(ipstr,4,';');
ssclint[whport].Timeout:=60;
ssclint[whport].Options.IPVersion:=ivipboth;
ssclint[whport].Options.ServerAliveCountMax:=3;
//
ssclint[whport].OnServerKeyValidate:=ssclint[whportdtb.prtid].SClientKeyValidation;
ssclint[whport].BeforeConnect:=ssclint[whportdtb.prtid].SClientBeforeConnect;
ssclint[whport].AfterConnect:=ssclint[whportdtb.prtid].SClientAfterConnect;
ssclint[whport].AfterDisconnect:=ssclint[whportdtb.prtid].SClientAfterDisconnect;
end else
begin
crteans:=1;
debuginfo(wavepath,' SSHClient Not Created',0);
end;
end else
begin
crteans:=1;
debuginfo(wavepath,' File Storage Not Created',0);
end;
end;
createssclient:=crteans;
end;
Function Connect_Client(whport:integer):integer;
var isconnect:integer;
begin
if ssfiles=nil then ssfiles:=TScFileStorage.create(nil);
if ssfiles<>nil then
begin
isconnect:=1;
ssfiles.Path:=wavepath;
connans:=createssclient(whport);
if connans=0 then
begin
try
ssclint[whport].Connect;
except Showmessage('Error Connecting to SSHClient',0); end;
if ssclint[whport].Connected then
begin
isconnect:=0;
end;
end;
end;
function find_sstelnetsocket(hoststr:string; hostprt:integer):integer;
var ert,scktfnd:integer;
begin
scktfnd:=-1;
with portvars^ do
begin
ert:=0;
while ((ert<=maxrecords) and (scktfnd=-1)) do
begin
try
if ((ssclint[ert]<>nil) and (hoststr=ssclint[ert].HostName) and (hostprt=ssclint[ert].Port)) then
begin
scktfnd:=ert;
end;
except
on e:exception do scktfnd:=-1;
end;
ert:=ert+1;
end;
end;
find_sstelnetsocket:=scktfnd;
end;
procedure tsshcclient.SClientBeforeConnect(Sender: TObject);
var fnddev:integer;
begin
fnddev:=find_sstelnetsocket(tsshcclient(sender).HostName,tsshcclient(sender).Port);
//tsshcclient(sender).HostName - Matches our Hostname of our test server
//tsshcclient(sender).Port - Matches our Port Number of our test server
//tsshcclient(sender).User - Matches our Username of our test server
//tsshcclient(sender).Password - Matches our Password of our test server
end;
procedure tsshcclient.SClientAfterConnect(Sender: TObject);
var fnddev:integer;
begin
fnddev:=find_sstelnetsocket(tsshcclient(sender).HostName,tsshcclient(sender).Port);
end;
procedure tsshcclient.SClientAfterDisconnect(Sender: TObject);
var fnddev:integer;
begin
fnddev:=find_sstelnetsocket(tsshcclient(sender).HostName,tsshcclient(sender).Port);
end;
procedure tsshcclient.SClientKeyValidation(Sender:tobject; Newserverkey:TSckey; var Accept:boolean);
begin
Accept:=true;
end;