Académique Documents
Professionnel Documents
Culture Documents
HowcanIcreateanSSHconnectionfromaC#application?StackOverflow
30
help
HowcanIcreateanSSHconnectionfromaC#application?
IamworkingoncreatingaGUItointerfacewithaCitrixXENserver.Idontknowhowtoexecutecommandsfrommywithinmyapplication
onmywidowssystemontheXENServer.IwasthinkingusingSSHbutagainIdontknowhow.Doesanyonehaveanexampleofhowto
dothis?HowtoestablishaSSHtunnelwhentheuserpushesabutton?Iwanttobeabletorunthecommandxevmlistandthendisplay
theoutputinalabel.ThatsjusttostartmynextonewillbetocreateaVMandnameiswhattheuserwants,butfornowIjustneedtofigure
outhowtoexecutecommandsontheXENServer.
c# ssh
editedNov1'10at16:23
mikerobi
11.4k
askedNov1'10at16:20
user770022
26
34
764
22
39
Seealsostackoverflow.com/questions/11169396/MarkJ Apr10'14at22:25
2Answers
Findingyourselfansshcomponentwillallowyoutodomoremeaningfulthings,butatthebase
level,youcandosomethinglikethis:
publicvoidExecuteExternalCommand(stringcommand)
{
try
{
//processstartinfo
System.Diagnostics.ProcessStartInfoprocessStartInfo=new
System.Diagnostics.ProcessStartInfo("cmd","/c"+command);
processStartInfo.RedirectStandardOutput=true;
processStartInfo.UseShellExecute=false;
processStartInfo.CreateNoWindow=true;//Don'tshowconsole
//createtheprocess
System.Diagnostics.Processprocess=newSystem.Diagnostics.Process();
process.StartInfo=processStartInfo;
process.Start();
stringoutput=process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
}
catch(Exceptionexception)
{
//TODO:somethingMeaninful
}
}
Whichwillletyourunarbitraryexternalexecutablesviathecmd.exeinterfaceandthenrespond
toit.
Here'ssomeLinks:
ExampleCode'sSSHComponent
[MSDNProcessClassdocs][2]
answeredNov1'10at16:39
lscoughlin
820
12
http://stackoverflow.com/questions/4070806/howcanicreateansshconnectionfromacsharpapplication
1/2
4/13/2015
HowcanIcreateanSSHconnectionfromaC#application?StackOverflow
IhaveusedSharpSSHwithgreatsuccess.
Thiscanbedownloadedfromhttp://www.tamirgal.com/blog/page/SharpSSH.aspx .
answeredNov1'10at16:26
PietervanGinkel
18.3k
34
68
IhaveusedSharpSSHtoo,it'snotveryreliable...Ihadtofixafewbugsmyselftobeabletomakeit
workcorrectly ThomasLevesqueNov1'10at16:55
http://stackoverflow.com/questions/4070806/howcanicreateansshconnectionfromacsharpapplication
2/2