Posts

Showing posts from September, 2010

Using Plink.exe from C# (accessing a linux PC)

T here seems to be a lot of questions on the web from people trying to access a linux from C#, most of them having problems using 'Plink'. This comes with 'Putty' and allows you to run remote commands on a linux machine. For this example, you have to use Putty to create and store a session using a public key. This makes automated login safer and more secure. The following code runs the 'ls' command on the remote session, called "quarch". Note the redirect of both standard in and standard out! System.Diagnostics. ProcessStartInfo ProcStart; System.Diagnostics.Process Proc; string Result; System.IO.StreamReader Output; ProcStart = new System.Diagnostics. ProcessStartInfo(@"c:\program files\putty\plink.exe"); ProcStart.Arguments = "-load quarch ls"; ProcStart. RedirectStandardOutput = true; ProcStart. RedirectStandardInput = true; ProcStart.