What is 'plink'? -> Press 'y' and enter. After that it might show some welcome message and the 'Last login' message. Now you have established your SSH connection.
|
>>Code:-
public void EstablishSshConnection()
{ ProcessStartInfo psi = new ProcessStartInfo(@"C:\Windows\System32\cmd"); psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; psi.UseShellExecute = false; psi.CreateNoWindow = false; Process process = Process.Start(psi); string cmdForTunnel = "plink -L 8888:localhost:3306 test@mindfiresolutions.com -pw abcd123"; process.StandardInput.WriteLine(cmdForTunnel); process.WaitForExit(); Thread.Sleep(10000); DoBusinessLogic(); process.StandardInput.WriteLine("logout"); Thread.Sleep(10000); if (process.HasExited) { process.Close(); process.Dispose(); } } Remember to sync the command prompt's directory path with the plink.exe file's path. When you open the command prompt using C# code, the default directory path is set to "C:\Windows\System32" as in some Windows OS (Windows 7). So, in that case you need to place the plink.exe file in "C:\Windows\System32" folder or else the plink command-line won't execute. |
C# application
最新推荐文章于 2024-04-01 16:10:21 发布
C# application