Re: Login, su to root, execute command (General questions)
hi,
i just downloaded the trial version of WodSSH...
i have trouble with the WaitFor method...
is the regex feature working with the trial version ?
here is the code (i just copy/paste/modify the code you provided)
The first WaitFor is blocking the application (timeout)
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
Dim Ssh1 As New WeOnlyDo.Client.SSH
Dim hostname As String, login As String, password As String, rootpass As String
Hostname = host
login = login
password = pass
rootpass = rootpass
Ssh1.Hostname = hostname
Ssh1.Login = login
Ssh1.Password = password
Ssh1.Blocking = True
Ssh1.Connect()
' once connected, wait for prompt
Ssh1.WaitFor( regex:[$ #>] $ , 5)
' if anything left in incoming buffer, delete it
If Ssh1.DataReady > 0 Then Ssh1.Receive()
' execute su command, wait for password prompt
Ssh1.Execute( su -
, Password: , 5)
' send password and wait for command prompt
Ssh1.Send(rootpass +
)
Ssh1.WaitFor( regex:[$ #>] $ , 5)
' if anything left in incoming buffer, delete it
If Ssh1.DataReady > 0 Then Ssh1.Receive()
' execute command and dump it's output to a messagebox
MessageBox.Show(Ssh1.Execute( ls -al
, regex:[$ #>] $ , 10))
' and disconnect
Ssh1.Disconnect()
End Sub