J'ai trouvé un code sur le forum Anglais que j'ai un peu adapté, pour tout dire c'est un peu complexe pour moi, mais ca marche, enfin presque.
Il suffit de récupérer Putty, j'utilise le fichier Plink.exe de Putty comme client SSH en mode console, la particularitée de Plink, c'est que l'on peut mettre le password en ligne de commande :
PLINK -ssh -2 -l lpastor -pw
12345 127.0.0.1
Openssh n'autorise pas cela.
Pour ceux que ca intéresse voici un autre serveur SSH en freeware pour Windows, ils sont particulièrement rares et celui la est le plus simple de tous à configurer et à utiliser :
http://www.freesshd.com/
Voici mon nouveau code, le problème c'est que je ne sais pas interagir avec les réponses, comment lui envoyer une commande en cours de fonctionnement ?
Code : Tout sélectionner
; Redirect Outputs into Memory
; coded by Siegfried Rings march 2002
; redirected the pipes
;
;see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173085
;
;mCommand.s="ssh"
mCommand.s="PLINK -ssh -2 -l lpastor -pw 12345 127.0.0.1"
;Structure used by the CreateProcessA function
;another then that Fred implemented !
Structure MySTARTUPINFO
cb.l
lpReserved.l
lpDesktop.l
lpTitle.l
dwX.l
dwY.l
dwXSize.l
dwYSize.l
dwXCountChars.l
dwYCountChars.l
dwFillAttribute.l
dwFlags.l
wShowWindow.w
cbReserved2.w
lpReserved2.l
hStdInput.l
hStdOutput.l
hStdError.l
EndStructure
proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
ret.l ;long variable For get the Return value of the
start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA
sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
hReadPipe.l ;Read Pipe handle created by CreatePipe
hWritePipe.l ;Write Pite handle created by CreatePipe
lngBytesread.l ;Amount of byte Read from the Read Pipe handle
strBuff.s=Space(256) ;String buffer reading the Pipe
;Consts For functions
#NORMAL_PRIORITY_CLASS = $20
#STARTF_USESTDHANDLES = $100
#STARTF_USESHOWWINDOW = $1
;Create the Pipe
sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0)
If ret = 0
;If an error occur during the Pipe creation exit
MessageRequester("info", "CreatePipe failed. Error: ",0)
End
EndIf
start\cb = SizeOf(MySTARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
;set the StdOutput And the StdError output To the same Write Pipe handle
start\hStdOutput = hWritePipe
start\hStdError = hWritePipe
;Execute the command
ret = CreateProcess_(0, mCommand, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)
If ret <> 1
MessageRequester("Info","File Or command not found", 0)
End
Else
;MessageRequester("Info","PRG started..:",0)
EndIf
;Now We can ... must close the hWritePipe
ret = CloseHandle_(hWritePipe)
mOutputs.s = ""
;Read the ReadPipe handle
While ret<>0
ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0)
If lngBytesread>0
mOutputs = mOutputs + Left(strBuff, lngBytesread)
EndIf
Wend
;Close the opened handles
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadPipe)
;ret=CloseHandle_(hWritePipe)
;Return the Outputs property with the entire DOS output
MessageRequester("Info",mOutputs,0)
Voici mon ancien code un peux amélioré, qui marche lui aussi à moitié, il oblige à saisir le mot de passe dans la console :
Code : Tout sélectionner
prg= RunProgram ( "D:\CLEE\Développement\PB\Sources LP\SSH\ssh.exe", "-v -l lpastor 127.0.0.1", "D:\CLEE\Développement\PB\Sources LP\SSH" , #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Write )
; Ca, ca ne marche pas !
;prg=ShellExecute_(0, "open", "D:\CLEE\Développement\PB\Sources LP\SSH\ssh.exe", "-v -i laurent.ppk -l lpastor 127.0.0.1", "D:\CLEE\Développement\PB\Sources LP\SSH", #SW_SHOW )
n.l=0
ligne.s=""
If prg
While ProgramRunning (prg)
ligne=ReadProgramString (prg)
Debug (ligne)
If ligne="" And n=0
n=n+1
WriteProgramStringN(prg, "dir")
;MessageRequester("Information",ligne,#PB_MessageRequester_Ok)
EndIf
;MessageRequester("Good",ligne,#PB_MessageRequester_Ok)
Wend
EndIf
CloseProgram (prg)
MessageRequester("FIN","Fin du programme",#PB_MessageRequester_Ok)
Voila, maintenant je suis planté la...
Laurent