AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Funciones SSH
  • Principle
  • How to?
  • Direct sending of commands
  • Dialog with an SSH server
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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:
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)
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:
Mantiene activa la sesión SSH entre varios comandos enviados a un servidor SSH (mediante la función SSHCommand).
Esta nueva función está disponible a partir de WINDEV Suite SaaS 2025 - Update 2.
Detiene la sesión SSH que estaba activa para enviar una serie de comandos.
Esta nueva función está disponible a partir de WINDEV Suite SaaS 2025 - Update 2.

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.
SSHDisconnectShellCierra una sesión SSH abierta por SSHConnectShell.
SSHReadLee los datos que se encuentran en el búfer de salida de la sesión SSH.
SSHWriteEscribe los datos en la sesión SSH especificada.
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 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_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-type 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
Versión mínima requerida
  • Versión 20
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 28/03/2025

Señalar un error o enviar una sugerencia | Ayuda local