ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / SSH functions
  • Principle
  • How to?
  • Direct sending of commands
  • Dialog with an SSH server
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Principle
SSH (Secure Shell) is a secure network protocol used to establish an encrypted connection between two systems.
This protocol is often used for remote administration of servers, as it ensures the confidentiality and integrity of exchanged data, thus protecting against interception and attacks. This protocol enables remote commands to be executed securely on these machines.
A server can therefore support the secure SSH protocol to receive commands remotely.
In WLanguage, SSH functions can be used to execute commands via this protocol.
The protocol is SSH-2.
Two methods can be used to communicate with an SSH server:
  • Send the Shell commands directly,
  • Communicating with an SSH server.
Note: Files can be copied via SSH using SCP functions.
How to?

Direct sending of commands

The direct sending of commands is performed by <Variable sshSession>Command. The parameters for connecting to the SSH server must be described in an sshSession variable.
Example:
cMaSession is sshSession
buffSortie is Buffer
cMaSession.Address = "127.0.0.1"
cMaSession.Port = 22
cMaSession.User = "login"
cMaSession.UserPassword = "pass"
nExitCode is int
sSortie is string ANSI
sSortieErr is string ANSI
(nExitCode, sSortie, sSortieErr) = SSHCommand(cMaSession, SAI_Commande)
IF ErrorOccurred THEN
	Error(ErrorInfo(errFullDetails))
	RETURN
END
SAI_ExitCode = nExitCode
SAI_StdOut = UTF8ToString(sSortie)
SAI_StdErr = UTF8ToString(sSortieErr)
Note: By default, the SSHCommand function opens the SSH session, executes the command and then closes the SSH session.
New in SaaS
To execute multiple SSH commands without closing the SSH session, simply keep the SSH connection active and close it after executing the commands, using the following functions:
Keeps the SSH session active between several commands sent (via the <Variable sshSession>Command function) to an SSH server.
This new function is available from WINDEV Suite SaaS 2025 Update 2.
Stop the SSH session that was active to allow multiple commands to be sent as a group.
This new function is available from WINDEV Suite SaaS 2025 Update 2.

Dialog with an SSH server

The dialog with the SSH server is performed by the following functions:
<sshSession variable>.ConnectShellStarts a new SSH session of "Shell" type.
<sshSession variable>.DisconnectShellCloses an SSH session that was opened by <sshSession variable>.ConnectShell.
<sshSession variable>.ReadReads the data found on the output buffer of the SSH session.
<sshSession variable>.WriteWrites data into the specified SSH session.
The parameters for connecting to the SSH server must be described in an sshSession variable.
Step 1: Connect to the SSH server
Connection to the server is made using the WLanguage function <sshSession variable>.ConnectShell. This function expects a variable of type sshSession as a parameter, which contains the connection information to the SSH server:
  • server address,
  • username,
  • password,
  • port to use.
gSessionSSH is sshSession
gSessionSSH.Address = SAI_Serveur
gSessionSSH.Port = SAI_Port
gSessionSSH.User = SAI_User
gSessionSSH.UserPassword = SAI_Mot_de_passe
// Ouvre la session SSH
gSessionSSH.ConnectShell()
Remarks:
  • We recommend changing the default port (port 22). Since SSH is an extremely widespread protocol, it is also much "attacked".
  • It is advisable to filter the IPs authorized to access the SSH protocol.
Connection via a private/public key pair
You can also connect to the SSH server using a public/private key pair.
gSessionSSH is sshSession
gSessionSSH.Address = SAI_Serveur
gSessionSSH.Port = SAI_Port
gSessionSSH.User = SAI_User
gSessionSSH.PrivateKey = SAI_Clé_privée
gSessionSSH.PrivateKeyPassword = SAI_Mot_de_passe
// Ouvre la session SSH
gSessionSSH.ConnectShell()
In this case, the server has the public key (see your SSH server documentation for the necessary configuration).
The client (the connecting application) owns the private key.
Authentication is therefore performed by encrypting a text sent to the server. If the server is able to decrypt this text, it means that the client has the private key. This private key can be password-protected.
Step 2: Sending orders
Commands are sent via the <sshSession variable>.Write function. This function expects as parameter:
  • SSH connection, through variable type sshSession,
  • the Command to be executed, in a Buffer-type variable.
    The command sent must end with a <10>.
sCommande is Buffer = SAI_Commande_à_envoyer + Charact(10)
gSessionSSH.Write(sCommande)
Step 3: Reading the results
Results and outputs are read out using the WLanguage function <sshSession variable>.Read. This function reads the text returned by the SSH server.
Step 4: Disconnecting
Disconnecting from the SSH server is very simple, using the WLanguage function <sshSession variable>.DisconnectShell and passing the:
gSessionSSH.DisconnectShell()
Full example:
cMaSession is sshSession
cMaSession.Address = "127.0.0.1"
cMaSession.Port = 22
cMaSession.User = "login"
cMaSession.UserPassword = "pass"
IF cMaSession.ConnectShell THEN
	Info("Session Ouverte")
	bufSortie is Buffer = "data"
	cMaSession.Write(bufSortie)
	cMaSession.DisconnectShell()
END
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/18/2025

Send a report | Local help