出于某种目的,我需要通过SSH运行以下命令。但经过几个小时的尝试......没有什么可以帮助我的。
这是我需要使用plink(putty cmd version)执行的命令
我在vb.net中尝试过以下代码,但只有第1步可以挂起:(
Private Sub cmdTest_Click(sender As System.Object, e As System.EventArgs) Handles cmdTest.Click
Dim objProcess As System.Diagnostics.Process
intProcState = 0
objProcess = New System.Diagnostics.Process
objProcess.StartInfo.FileName = "c:\Program Files\PuTTY\plink.exe"
objProcess.StartInfo.Arguments = "-ssh -P {Port} root@{Host} -pw {PW}"
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.CreateNoWindow = False
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.StartInfo.RedirectStandardError = True
objProcess.StartInfo.RedirectStandardInput = True
objProcess.StartInfo.RedirectStandardOutput = True
AddHandler objProcess.OutputDataReceived, AddressOf consoleOutputHandler
AddHandler objProcess.ErrorDataReceived, AddressOf consoleErrorHandler
objProcess.Start()
objProcIn = objProcess.StandardInput
objProcess.BeginOutputReadLine()
objProcess.BeginErrorReadLine()
objProcess.WaitForExit()
objProcess.Dispose()
objProcess = Nothing
MessageBox.Show("done")
End Sub
Sub consoleOutputHandler(ByVal sendingProcess As Object, ByVal outLine As DataReceivedEventArgs)
If Not String.IsNullOrEmpty(outLine.Data) Then
If outLine.Data.IndexOf("Last login:") <> -1 Then
intProcState = 0
sRunCommand()
End If
If outLine.Data = "Connected to {sftp host}." Then
intProcState += 1
sRunCommand()
End If
If outLine.Data.Substring(outLine.Data.Length - 2) = "# " Then
intProcState += 1
sRunCommand()
End If
End If
End Sub
Private Sub sRunCommand()
Select Case intProcState
Case 0
objProcIn.WriteLine("sftp -P {Port} user@{Host}")
System.Threading.Thread.Sleep(2000)
objProcIn.WriteLine("{PW}")
Case 1
objProcIn.WriteLine("put DL/test.test /home1/user/public_html/DL/test.test")
Case 2
objProcIn.WriteLine("bye")
Case 3
objProcIn.WriteLine("logout")
End Select
End Sub
有没有更好的方法来处理它?</ p>
我知道chilkatsoft SSH可以处理它,但我对该组件非常新手。
提前致谢
最好的问候