I've been trying to send a simple line that needs sudo permission on VB.net. I can't use expect inside the SSH request because it's not avaible on my server, which is a Synology
I tried two options:
Dim coString As New Renci.SshNet.PasswordConnectionInfo(serv, port, name, dsPass)
Dim sshClient As New Renci.SshNet.SshClient(coString)
Dim cmd1 As Renci.SshNet.SshCommand
Dim commandString As String = "echo ""plaintext_key"" | sudo -S synoshare --enc_mount genericFolderName myPassphrase"
Try
sshClient.Connect()
test.progress.Value = 10
cmd1 = sshClient.RunCommand(commandString)
sshClient.Disconnect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
This just skip sshClient.RunCommand(commandString)
after a few seconds but does nothing.
Dim coString As New Renci.SshNet.PasswordConnectionInfo(serv, port, name, dsPass)
Dim sshClient As New Renci.SshNet.SshClient(coString)
Dim modes As New Dictionary(Of Renci.SshNet.Common.TerminalModes, UInt32)
Try
sshClient.Connect()
Dim stream = sshClient.CreateShellStream("xterm", 255, 50, 800, 600, 1024, modes)
Using stream
test.progress.Value = 10
stream.Write("sudo synoshare --enc_unmount genericFolderName")
stream.Expect("Password: ")
stream.Write(dsPass)
End Using
sshClient.Disconnect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
This one just get stuck forever at stream.Expect("Password: ")
. I tried to replace Password:
(What is written when you type it into the SSH Console) with Password:
and password
but it didn't change anything.