I am working on creating a GUI to interface with a Citrix XEN server. I dont know how to execute commands from my within my application on my widows system on the XEN Server. I was thinking using SSH but again I dont know how. Does anyone have an example of how to do this? How to establish a SSH tunnel when the user pushes a button? I want to be able to run the command xe vm-list and then display the output in a label. Thats just to start my next one will be to create a VM and name is what the user wants, but for now I just need to figure out how to execute commands on the XEN Server.
Asked
Active
Viewed 1.7k times
3
-
See also http://stackoverflow.com/questions/11169396/c-sharp-send-a-simple-ssh-command – MarkJ Apr 10 '14 at 22:25
2 Answers
2
I have used SharpSSH with great success.
This can be downloaded from http://www.tamirgal.com/blog/page/SharpSSH.aspx.

Pieter van Ginkel
- 29,160
- 8
- 71
- 111
-
-
The source file from sourceforge has an `Examples\sharpssh_samples` folder which contains a lot of samples which go into a lot of detail. – Pieter van Ginkel Nov 01 '10 at 16:30
-
this is not what I was looking for. I want it to all be hidden from the user. – user770022 Nov 01 '10 at 16:46
-
1These classes allow you to connect with an SSH server without a console. The `SshExec` class has a `RunCommand` method which does exactly that. – Pieter van Ginkel Nov 01 '10 at 16:50
-
I have used SharpSSH too, it's not very reliable... I had to fix a few bugs myself to be able to make it work correctly – Thomas Levesque Nov 01 '10 at 16:55
-
1
Finding yourself an ssh component will allow you to do more meaningful things, but at the base level, you can do something like this:
public void ExecuteExternalCommand(string command)
{
try
{
// process start info
System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.CreateNoWindow = true; // Don't show console
// create the process
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = processStartInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
}
catch (Exception exception)
{
//TODO: something Meaninful
}
}
Which will let you run arbitrary external executables via the cmd.exe interface and then respond to it.
Here's some Links:
- Example Code's SSH Component
- [MSDN Process Class docs][2]

lscoughlin
- 2,327
- 16
- 23