|
Envois d'un message par SSH avec la DLL ExtraPuTTY.dll |
Débuté par Olivier, 10 nov. 2015 12:41 - 2 réponses |
| |
| | | |
|
| |
Posté le 10 novembre 2015 - 12:41 |
Bonjour, Je souhaite communiquer avec un switch en SSH, ma version actuelle de Windev est la 17, en attendant la sortie de la version 20 qui gère les fonction SSH, je souhaite utiliser la DLL ExtraPuTTY.dll. malheureusement mon programme (voir au dessous) n'arrive ni a se connecter ni a envoyer la commande, je ne trouve pas mon erreur. S'il vous plait un peu d'aide.
voici les deux fonctions que je veux utiliser dans cette DLL:
FONCTION "Connexion"
SYNTAX:
int Connexion(char *TargetName,unsigned long *ConnectionId,char *Login,char *Password,bool ShowPuTTY,long Protocol,unsigned long PortNumber,long GenerateReport,int *CallBackRcvData,unsigned long SpecSettings);
PARAMETRES:
TargetName: TargetName or PuttySession Name (in this case Protocol must be equalt to 4). ConnectionId: Connection ID. Login: Optional parameter. le login du switch Password: Optional parameter. Le mot de passe du switch ShowPuTTY: TRUE: Putty Terminal is display, FALSE: not display. Protocol: 0:Telnet,1:SSH,2:Rlogin,3:Raw,4:LoadPutty Session,5:Serial Link,6:Cygterm. PortNumber: If the parameter is set to 0, the value of the default settings of putty is used. This field correspond to the speed for serial line protocol. GenerateReport: 1:extraputty report activate,0:Not activate. CallBackRcvData: Optional parameter,callback used to receive data from putty terminal, Syntax : int CallBackRcvData(unsigned long ConnectionId,char *buf, DWORD size,DWORD ConnectionStatus) ConnectionStatus : 0 : Connection open 1 : Connection close by host
VALEURS DE RETOUR:
0: Indicates that the function successfully to establish the connection. <> 0: Indicates that the function was unable to establish the connection. 1: ExtraPutty environment vairable doesn't exist. 2: Wrong value of parameter Protocol (0-6).
FONCTION "SendRcvData_O"
SYNTAX:
int SendRcvData_O(unsigned long ConnexionId,char *Command,char *Title,char *Comments,long TimeCapture,char *DataRcv,long MaxSizeofData,unsigned long settings); PARAMETRES:
ConnectionId: ConnectionId set by Connexion function (shall be > 0). Command: Data to send on the target, if the parameter is null the function is configured only in reception way. Title: Title of your command,used only if extraputty report is activate. Comments: Comments of your command,used only if extraputty report is activate. TimeCapture: Time used to capture the reply data in ms. DataRcv: Buffer which contains the data received if TimerCapture is > 0. MaxSizeofData: Size of DataRcv Buffer or maximum data size in DataRcv (1 < MaxSizeofData < 20 000 000) Settings Bit fields of settings (2^0 : CRLF (0 send,1 not send),2^1 : Virtual key codes (0 no virtual key codes in command,1 yes)...reserved)
VALEURS DE RETOUR:
0: Indicates that the function successfully to Send\Received data. <> 0: Indicates that the function was unable to Send-Received data.
MON CODE (inspiré du code posté http://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/146530-wd17-connexion-ssh-linux-40473/read.awp
La connexion:
nIdDLL est un entier nIdDLL = ChargeDLL("ExtraPuTTY.dll") SI nIdDLL = 0 ALORS Erreur("Erreur lors du chargement de la DLL") SINON Trace(nIdDLL)
FIN nResultat est un entier Connexion est une Description d'API Connexion.NomDLL = "ExtraPuTTY.dll" Connexion.NomFonction = "Connexion" IDConnexion est un entier sur 8 octets
Ip est une chaîne Ip = "192.168.1.122" sPassword est une chaîne sPassword = "motdepass" nPort est un entier sur 8 octets nPort = 22 sUser est une chaîne sUser = "test"
nResultat = AppelDLL32(Connexion.NomDLL, Connexion.NomFonction,"192.168.1.122",&IDConnexion, &sUser,&sPassword, False, 1, nPort, 0, &CallBackRcvData, 0)
SI nResultat <> 0 ALORS Trace("Non connecté") RETOUR SINON Trace(nResultat) FIN La procédure:
Procedure CallBackRcvData(ip est un entier, Buff est un chaîne, Size est un entier, ConnectionStatus est un entier)
VbBuf est une chaîne ASCIIZ sur 10000
SI (Size > 0) ET (ConnectionStatus = 0) ALORS VbBuf = Complete(Size + 5, Null) API("kernel32", "RtlMoveMemory", &VbBuf, Buff, Size) Trace(VbBuf) SINON SI (ConnectionStatus <> 0) ALORS Erreur("Connection closed by remote host") FIN Envoie de la commande
sTamponReception est une chaîne sur 10000 sTamponReception = Répète(Null, 10000) sCommande1 est une chaîne
SendRcv est une Description d'API SendRcv.NomDLL="ExtraPuTTY.dll" SendRcv.NomFonction="SendRcvData_O"
sCommande1 ="tool send message=salut number=0798955614 port=usb5 channel=0" nResultat = AppelDLL32(SendRcv.NomDLL, SendRcv.NomFonction,"192.168.1.122",sCommande1, "", "", 5000, &sTamponReception, 10000, 0)
SI nResultat <> 0 ALORS Trace("Non envoyé") RETOUR FIN Trace(nResultat) |
| |
| |
| | | |
|
| | |
| |
Posté le 10 novembre 2015 - 20:02 |
c'est bon j'ai réussi à résoudre le problème, je poste ma solution pour le prochain qui souhaite faire la même application. voici le code:
Connexion et envoie de la commande:
IDConnexion est un entier sur 8 octets nResultat est un entier Connexion est une Description d'API Connexion.NomDLL = "ExtraPuTTY.dll" Connexion.NomFonction = "Connexion"
Ip est une chaîne Ip = "192.168.1.122" sPassword est une chaîne sPassword = "MotDePasseServeur" nPort est un entier sur 8 octets nPort = 22 sUser est une chaîne sUser = "Utilisateur"
nResultat = AppelDLL32(Connexion.NomDLL, Connexion.NomFonction,"192.168.1.122",&IDConnexion, sUser,sPassword, False, 1, nPort, 0, &CallBackRcvData, 0) SI nResultat <> 0 ALORS Trace("Non connecté") SINON Trace("Résultat de la connexion est ",nResultat) FIN
sTamponReception est une chaîne sTamponReception = Répète(Null, 100000) sCommande est une chaîne SendRcv est une Description d'API SendRcv.NomDLL="ExtraPuTTY.dll" SendRcv.NomFonction="SendRcvData_O"
sCommande ="commande à envoyer"
Trace(sCommande) nResultat = AppelDLL32(SendRcv.NomDLL, SendRcv.NomFonction,IDConnexion,&sCommande,"","", 50, &sTamponReception, 10000, 0) SI nResultat <> 0 ALORS Trace("Non envoyé") SINON Trace("Resultat d'envois de commande est ", sTamponReception) FIN Trace(sCommande)
La procédure CallBackRcvData:
Procedure CallBackRcvData( ip est un entier, Buff est un chaîne, Size est un entier, ConnectionStatus est un entier)
VbBuf est une chaîne ASCIIZ sur 10000
SI (Size > 0) ET (ConnectionStatus = 0) ALORS VbBuf = Complete(Size + 5, Null) VbBuf=API("kernel32", "RtlMoveMemory", &VbBuf, Buff, Size)
SINON SI (ConnectionStatus <> 0) ALORS Erreur("Connection closed by remote host") FIN RENVOYER 0 Voilà voilà |
| |
| |
| | | |
|
| | |
| |
Posté le 08 mai 2017 - 12:51 |
un grand merci à toi olivier |
| |
| |
| | | |
|
| | | | |
| | |
|