ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
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 remote commands.
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:
Note: Files can be copied via SSH using SCP functions.
How to?

Direct sending of commands

The direct sending of commands is performed by SSHCommand. The parameters for connecting to the SSH server must be described in an sshSession variable.
Example:
cMySession is sshSession
buffOutput is Buffer
cMySession.Address = "127.0.0.1"
cMySession.Port = 22
cMySession.User = "login"
cMySession.UserPassword = "pass"
nExitCode is int
sOutput is ANSI string
sOutputErr is ANSI string
(nExitCode, sOutput, sOutputErr) = SSHCommand(cMySession, EDT_Command)
IF ErrorOccurred THEN
	Error(ErrorInfo(errFullDetails))
	RETURN
END
EDT_ExitCode = nExitCode
EDT_StdOut = UTF8ToString(sOutput)
EDT_StdErr = UTF8ToString(sOutputErr)

Dialog with an SSH server

The dialog with the SSH server is performed by the following functions:
SSHConnectShellStarts a new SSH session of "Shell" type.
SSHDisconnectShellCloses an SSH session that was opened by SSHConnectShell.
SSHReadReads the data found on the output buffer of the SSH session.
SSHWriteWrites 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 SSHConnectShell. This function expects a sshSession variable as a parameter, which contains the SSH server connection information:
  • server address,
  • username,
  • password,
  • port to use.
gSessionSSH is sshSession
gSessionSSH.Address = SAI_Server
gSessionSSH.Port = SAI_Port
gSessionSSH.User = SAI_User
gSessionSSH.UserPassword = SAI_Password
// Open SSH session
SSHConnectShell(gSessionSSH)
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_Server
gSessionSSH.Port = SAI_Port
gSessionSSH.User = SAI_User
gSessionSSH.PrivateKey = SAI_PrivateKey
gSessionSSH.PrivateKeyPassword = SAI_Password
// Open SSH session
SSHConnectShell(gSessionSSH)
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 SSHWrite function. This function expects as parameter:
  • SSH connection, through variable type sshSession,
  • the command to be executed, in a Buffer variable.
    The command sent must end with a <10>.
sOrder is TO Buffer = SAI_Commande_ à_envoyer + Charact(10)
SSHWrite(gSessionSSH, sOrder)
Step 3: Reading the results
Results and outputs are read out using the WLanguage function SSHRead. 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 SSHDisconnectShell and passing the:
SSHDisconnectShell(gSessionSSH)
Full example:
cMySession is sshSession
cMySession.Address = "127.0.0.1"
cMySession.Port = 22
cMySession.User = "login"
cMySession.UserPassword = "pass"
IF SSHConnectShell(cMySession) THEN
	Info("Session started")
	bufOutput is Buffer = "data"
	SSHWrite(cMySession, bufOutput)
	SSHDisconnectShell(cMySession)
END
Minimum version required
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 02/25/2025

Send a report | Local help