Page 1 of 1

SSHClient and SSHCustomChannel

Posted: Thu 30 Sep 2021 01:39
by MRoth
Hello,

We are working in Delphi 2007.

We need to add an SSHClient to our application. We currently have connections to TCP/IP servers, FTP servers and Telnet Servers. We create all classes at runtime. Do you have an example on how we can create these classes at runtime.

We want to use the SSHCustomChannel because we need to be notified when data is received from the server. We want to add the TScAsyncReceiveEvent = procedure(Sender: TObject) of object; to the class. See below.

Also, we are using atPassword for the Authentication. Do we need to add TScFileStorage for password authentication.

Our application can connect to a number of servers. We added the devicenum and portnum fields to the class so we can tell when data is received in the socket1OnAsyncReceive what device it is associated with. Will this be included in the Sender:Tobject.

tsshsocket=class(TScSSHCustomChannel)
public
devicenum:integer;
portnum:integer;
procedure socket1OnAsyncError(Sender: TObject; E: Exception)
procedure socket1OnAsyncReceive(Sender: TObject);
procedure socket1OnConnect;
procedure socket1disconnect;
end;

tsshcclient=class(TScSSHClient)
public
devicenum:integer;
portnum:integer;
end;

Thanks for all your help.

Re: SSHClient and SSHCustomChannel

Posted: Fri 01 Oct 2021 06:54
by YanishevskiyVI
Hi!

Thank you for your question!

Please be informed, that TScFileStorage (alternatively TScRegStorage or TScMemoryStorage) is necessary for storing server keys, used while connection establishing even if username/password authentication used.

In order to create a connection, for each instance of host+port a separate TScSSHClient should be created. (a same TScStorage can be assigned for all)
You may create a desired amount of TScSSHChannel components connected to a same TScSSHClient by assigning TScSSHChannel.Client property.

Please note that TScSSHChannel already has a published OnAsyncReceive:TScAsyncReceiveEvent property.
Since TScSSHChannel is coupled with TScSSHClient, you may identify event source by
- Sender reference
- TScSSHChannel(Sender).Client
- TScSSHChannel(Sender).Client.Host
- TScSSHChannel(Sender).Client.Port

Please, let us know if you have any questions!

Regards,
Vitaliy

Re: SSHClient and SSHCustomChannel

Posted: Fri 01 Oct 2021 17:11
by MRoth
Hello Vitaliy,

Thank you that was very helpful.

One question you stated "You may create a desired amount of TScSSHChannel components connected to a same TScSSHClient by assigning TScSSHChannel.Client property."

What if they have different host, port, username and password. Doesn't the SSHClient need a host and port number.

Re: SSHClient and SSHCustomChannel

Posted: Tue 05 Oct 2021 05:32
by YanishevskiyVI
Hi,

Please, kindly note that since each user within a same host have it's own environment, connecting with different users credentials can be imaged as a connecting to a virtually different host.

Thus, a separate TScSSHClient must be created to login with different user credentials.

Please, also don't be confused with DestHost, DestPort, SourcePort properties of TScSSHChannel, since they are used in case of port forwarding tasks: https://www.devart.com/sbridge/docs/ind ... ciples.htm

Regards,
Vitaliy