Je viens vers vous car j'ai commencé à développer quelques script via ce magnigique outil qu'est AutoIt et je rencontre un problème pour l'un d'eux, vous l'aurez compris via le titre, lors de tentative de connexion SFTP.
Je tiens à présenter mes excuses par avance, mais je suis nouveau sur ce forum et débutant en programmation AutoIt (en programmation tout court en fait...


Voici le problème que je rencontre :
J'ai un programme "MonTraitement.exe" qui effectue un connexion vers un serveur SFTP. Pour réaliser cette connexion, j'utilise la bibliothéque SFTPEx.au3 et le programme psftp.exe.
Pour la faire courte, ce programme tourne toutes les 15 minutes sur un groupe de machine (1200 machines environ). Bien évidemment je logue toutes mes actions ce qui m'a permis de me rendre compte que parfois, mon traitement se lançait et ne se terminait jamais. Aprés analyse, il semble qu'il bloque sur la connexion SFTP et ne récupére jamais la main.
J'ai donc analysé les logs coté serveur SFTP et nous avons observé un problème d'identification. En fait, plutôt que de passer le bon User, le user envoyé lors de la tentative de connexion est "y"
En analysant le code de la bibliothéque SFTPEx.au3 et plus particuliérement la fonction de _SFTP_connect, j'ai observé ceci :
Func _SFTP_Connect($hSession, $sServerName, $sUsername = "", $sPassword = "", $iServerPort = 0)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
EndIf
If $iServerPort = 0 Then
$iServerPort = ""
EndIf
Local $sLine, $sStringSplit, $iWaitKeySaving = 0, $bSaveKey = True
StdinWrite($hSession, 'open ' & $sServerName & ' ' & $iServerPort & @CRLF)
While 1
$iWaitKeySaving += 1
If $iWaitKeySaving >= 500 And $bSaveKey Then
StdinWrite($hSession, 'y' & @CRLF)
$bSaveKey = False
EndIf
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop
ElseIf StringInStr($sLine, "login as:") Then
StdinWrite($hSession, $sUsername & @CRLF)
While 1
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop 2
ElseIf StringInStr($sLine, "password:") Then
StdinWrite($hSession, $sPassword & @CRLF)
ExitLoop 2
EndIf
Sleep(10)
WEnd
ElseIf $sLine <> "" Then
Return SetError(3, 0, 0)
EndIf
Sleep(10)
WEnd
If $sLine <> "psftp>" Then ; Connection With User And Password.
While 1
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop
ElseIf StringInStr($sLine, "Access denied") Then
Return SetError(2, 0, 0) ; The Password Is Required Again.
EndIf
Sleep(10)
WEnd
EndIf
If StringInStr($sLine, "Remote working directory is") Then
$sStringSplit = StringSplit($sLine, @CRLF)
$__gsRemoteDir_SFTP = StringTrimLeft($sStringSplit[1], 28)
EndIf
If $__gsRemoteDir_SFTP = 0 Then
$__gsRemoteDir_SFTP = _SFTP_DirGetCurrent($hSession)
EndIf
Return $hSession
EndFunc ; ==>_SFTP_Connect
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
EndIf
If $iServerPort = 0 Then
$iServerPort = ""
EndIf
Local $sLine, $sStringSplit, $iWaitKeySaving = 0, $bSaveKey = True
StdinWrite($hSession, 'open ' & $sServerName & ' ' & $iServerPort & @CRLF)
While 1
$iWaitKeySaving += 1
If $iWaitKeySaving >= 500 And $bSaveKey Then
StdinWrite($hSession, 'y' & @CRLF)
$bSaveKey = False
EndIf
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop
ElseIf StringInStr($sLine, "login as:") Then
StdinWrite($hSession, $sUsername & @CRLF)
While 1
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop 2
ElseIf StringInStr($sLine, "password:") Then
StdinWrite($hSession, $sPassword & @CRLF)
ExitLoop 2
EndIf
Sleep(10)
WEnd
ElseIf $sLine <> "" Then
Return SetError(3, 0, 0)
EndIf
Sleep(10)
WEnd
If $sLine <> "psftp>" Then ; Connection With User And Password.
While 1
$sLine = StdoutRead($hSession)
If ProcessExists($hSession) = 0 Then
Return SetError(1, 0, 0)
ElseIf StringInStr($sLine, "psftp>") Then
ExitLoop
ElseIf StringInStr($sLine, "Access denied") Then
Return SetError(2, 0, 0) ; The Password Is Required Again.
EndIf
Sleep(10)
WEnd
EndIf
If StringInStr($sLine, "Remote working directory is") Then
$sStringSplit = StringSplit($sLine, @CRLF)
$__gsRemoteDir_SFTP = StringTrimLeft($sStringSplit[1], 28)
EndIf
If $__gsRemoteDir_SFTP = 0 Then
$__gsRemoteDir_SFTP = _SFTP_DirGetCurrent($hSession)
EndIf
Return $hSession
EndFunc ; ==>_SFTP_Connect
L'interprétation que j'en fais, c'est qu'au final, la connexion est authentifiée et que le programme répond "y" à une question qui ne lui est pas/plus posée. (mea-culpa si je suis à coté de la plaque

Voici le bout de code de mon programme :
$sPath = "psftp.exe"
$hSession = _SFTP_Open($sPath)
sleep(100)
$hConnection = _SFTP_Connect($hSession, $server, $username, $passwd, $Port)
$hSession = _SFTP_Open($sPath)
sleep(100)
$hConnection = _SFTP_Connect($hSession, $server, $username, $passwd, $Port)
Ce que je ne comprends pas c'est pourquoi, la plupart du temps le programme fonctionne et parfois il bloque. Si c'était un problème d'identification du user, il devrait bloquer tout le temps non ?
Ma question au final est : Comment faire pour ne pas rencontrer ce problème ?
N'hésites pas à me dire si vous avez besoin de plus d'information.
Dans l'attente de votre retour,
D'avance merci à tous,
Sylvain.