jordane45
Messages postés38092Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention23 mars 2024
-
23 juin 2010 à 17:50
scoob79
Messages postés27Date d'inscriptionmercredi 20 janvier 2010StatutMembreDernière intervention 5 septembre 2018
-
16 août 2018 à 15:09
Bonjour à tous et toutes.
J'essai d'écrire un programme me permettant d'établir une connexion à un serveur en utilisant la DLL d'extraPutty, puis de lui envoyer des commandes.
A l'heure actuelle, j'arrive bien à établir la connexion mais par la suite, je n'arrive pas à envoyer de commandes. (il me retourne une erreur de connexion alors que je vois bien, dans la console putty, que je suis sur le serveur).
Le code est inspiré de l'exemple VB.NET donné sur le site d'ExtraPutty.
EXTRAPUTTY
voici ce que j'ai écrit :
Private Declare Function Connexion Lib "ExtraPuTTY.dll" (ByVal TragetName As String, ByRef ConnexionId As Long, ByVal Log As String, ByVal Pass As String, ByVal Display As Integer, ByVal proto As Long, ByVal portnumber As Long, ByVal rapport As Long, ByVal CallBackRcvData As Any) As Integer
Private Declare Function CloseAllConnexion Lib "ExtraPuTTY.dll" () As Integer
Private Declare Function SendRcvData Lib "ExtraPuTTY.dll" (ByVal ConnexionId As Integer, ByVal Command As String, ByVal title As String, ByVal comment As String, ByVal capt As Integer, ByRef bufdata As Any, ByVal Sizedata As Integer, ByVal Settings As Integer) As Integer
'************************************** SendRcvData *******************************************************************
'Parameter Description
'ConnexionId Connexion ID 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),...reserved)
'****************************************************************************************************************************
Private Sub Command1_Click()
Dim result As Integer, CallBAckAdr As Long, ConnexionId_SSH As Long
CallBAckAdr = 0
'**********************************************************
' INFORMATIONS DE CONNEXION
'**********************************************************
Nom_SRV = "SRV001TEST"
LOG_ID = "test"
LOG_PWD = "testmdp"
PuttyVisible = 1 '1=Oui 0=Non
CMD = "exit"
'**********************************************************
' Connexion au serveur
'**********************************************************
result = Connexion(Nom_SRV, ConnexionId_SSH, LOG_ID, LOG_PWD, PuttyVisible, 1, 22, 0, CallBAckAdr)
' test si la connexion est OK
If (result <> 0) Then
MsgBox "Erreur n° " & result
Else
MsgBox "Connecté " & result
SendCMD = SendRcvData(ConnexionId_SSH, CMD, "", "", 15000, DataRcv, 1000000, 0)
End If
'**********************************************************
' Fermer toutes les connexions
'**********************************************************
'CAC = CloseAllConnexion()
End Sub
Quelqu"un aurait-il une idée sur le sujet ?
Je ne suis pas sur de bien déclarer la fonction SendRcvData ni correctement l'appeller par la suite.
Bien sur, une fois la commande (CMD) passée, il faut aussi que je puisse récuperer les informations renvoyées par le serveur...
jordane45
Messages postés38092Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention23 mars 2024344 24 juin 2010 à 11:46
re,
J'ai trouvé comment faire :
Déclaration de la DLL :
Private Declare Function SendRcvData Lib "ExtraPuTTY.dll" (ByVal ConnexionId As Long, ByVal Command As String, ByVal title As String, ByVal comment As String, ByVal capt As Long, ByRef data As String, ByVal Sizedata As Long, ByVal Settings As Long) As Integer
Et ensuite, le Sub qui me permet d'envoyer la commande (une fois la connexion établie ):
Sub SendSSH(ConnexionId_SSH)
Dim Datarcv As String
Dim result As Integer
Dim CMD As String
CMD = "ls"
'Set the buffer with Null characters and send hello data
Datarcv = String(9999, vbNullChar)
result = SendRcvData(ConnexionId_SSH, CMD, "", "", 5000, Datarcv, 80, 1)
'Check the result of command
If (result <> 0) Then
MsgBox "Failed to send data"
Else
MsgBox Datarcv
End If
End Sub
Mon souci maintenant c'est ... comment valider ( fin de ligne ) une fois la commande envoyée ?
raysoukey
Messages postés1Date d'inscriptionsamedi 7 août 2010StatutMembreDernière intervention 7 août 2010 7 août 2010 à 18:31
Merci pour toutes ces informations!
J'utilise VB2008 express et il y a la variable CallBackRcvData que je ne peux pas déclarer "as any". Quel type devrais-choisir? Pour l'instant j'ai choisi "string"
Je n'arrive pas a me connecter via un autre port. C'est la seule différence dans le code de Jordane que j'ai utilisé. Pourtant je me branche sans aucun problème avec Putty.
Private Declare Function Connexion Lib "ExtraPuTTY.dll" (ByVal TragetName As String, ByRef ConnexionId As Long, ByVal Log As String, ByVal Pass As String, ByVal Display As Integer, ByVal proto As Long, ByVal portnumber As Long, ByVal rapport As Long, ByVal CallBackRcvData As String) As Integer
Private Declare Function CloseAllConnexion Lib "ExtraPuTTY.dll" () As Integer
Private Declare Function SendRcvData Lib "ExtraPuTTY.dll" (ByVal ConnexionId As Long, ByVal Command As String, ByVal title As String, ByVal comment As String, ByVal capt As Long, ByRef data As String, ByVal Sizedata As Long, ByVal Settings As Long) As Integer
'************************************** SendRcvData *******************************************************************
'Parameter Description
'ConnexionId Connexion ID 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),...reserved)
'****************************************************************************************************************************
Private Sub btnInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInit.Click
Dim result As Integer, CallBAckAdr As Long, ConnexionId_SSH As Long
Dim Nom_SRV As String, LOG_ID As String, LOG_PWD As String, PuttyVisible As Integer
CallBAckAdr = 0
'**********************************************************
' INFORMATIONS DE CONNEXION
'**********************************************************
Nom_SRV = "192.168.1.4"
LOG_ID = "login"
LOG_PWD = "password"
PuttyVisible = 1 '1=Oui 0=Non
'CMD = "exit"
'**********************************************************
' Connexion au serveur
'**********************************************************
result = Connexion(Nom_SRV, ConnexionId_SSH, LOG_ID, LOG_PWD, PuttyVisible, 1, 4118, 0, CallBAckAdr)
' test si la connexion est OK
If (result <> 0) Then
MsgBox("Erreur n° " & result)
Else
MsgBox("Connecté " & result)
'SendCMD = SendRcvData(ConnexionId_SSH, CMD, "", "", 15000, DataRcv, 1000000, 0)
End If
'**********************************************************
' Fermer toutes les connexions
'**********************************************************
'CAC = CloseAllConnexion()
scoob79
Messages postés27Date d'inscriptionmercredi 20 janvier 2010StatutMembreDernière intervention 5 septembre 2018 16 août 2018 à 15:07
Bonjour,
avec le même code j'ai un autre soucis je n'arrive pas à me connecter j'ai le message d'erreur suivant :
Private Declare Function SendRcvData Lib "ExtraPuTTY.dll" (ByVal ConnexionId As Long, ByVal Command As String, ByVal title As String, ByVal comment As String, ByVal capt As Long, ByRef data As String, ByVal Sizedata As Long, ByVal Settings As Long) As Integer
Dans un premier temps je pensais que le problème venais du fait que putty était ouvert, mais pas du tout. Ensuite j'ai, en faisant un CloseAllConnexion() pendant l’exécution, je me suis aperçu que cela faisait avancer le code jusqu’à la fin où la j'ai une erreur 1.
Quelqu'un à une idée ?
@+
Code :
Public Class Form1
Public Declare Function Connexion Lib "ExtraPuTTY.dll" (ByVal TragetName As String, ByRef ConnexionId As Long, ByVal Log As String, ByVal Pass As String, ByVal Display As Integer, ByVal proto As Long, ByVal portnumber As Long, ByVal rapport As Long, ByVal CallBackRcvData As Integer) As Integer
Public Declare Function CloseAllConnexion Lib "ExtraPuTTY.dll" () As Integer
Private Declare Function SendRcvData Lib "ExtraPuTTY.dll" (ByVal ConnexionId As Long, ByVal Command As String, ByVal title As String, ByVal comment As String, ByVal capt As Long, ByRef data As String, ByVal Sizedata As Long, ByVal Settings As Long) As Integer
'************************************** SendRcvData *******************************************************************
'Parameter Description
'ConnexionId Connexion ID 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),...reserved)
'****************************************************************************************************************************
Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim result As Integer, CallBAckAdr As Long, ConnexionId_SSH As Long
Dim Nom_SRV, LOG_ID, LOG_PWD, PuttyVisible, CMD, SendCMD, CAC
CallBAckAdr = 0
Dim isConnected As Long = 0
'**********************************************************
' INFORMATIONS DE CONNEXION
'**********************************************************
Nom_SRV = "10.69.115.12"
LOG_ID = "okaspar"
LOG_PWD = "!j3suis1G33K!"
PuttyVisible = 1 '1=Oui 0=Non
CMD = "exit"
'**********************************************************
' Connexion au serveur
'**********************************************************
CAC = CloseAllConnexion()
result = Connexion(Nom_SRV, isConnected, LOG_ID, LOG_PWD, PuttyVisible, 1, 22, 0, CallBAckAdr)
' test si la connexion est OK
If (result <> 0) Then
MsgBox("Erreur n° " & result)
Else
MsgBox("Connecté " & result)
'SendCMD = SendRcvData(ConnexionId_SSH, CMD, "", "", 15000, DataRcv, 1000000, 0)
End If
'**********************************************************
' Fermer toutes les connexions
'**********************************************************
CAC = CloseAllConnexion()
End Sub
End Class
16 août 2018 à 15:09
d'où elle sort la fonction je suis en vb 2010 ?
@++