0

ok folks i have seen alot of questions about this but none that i can use or understand

What i am attempting to do is connect to putty from asp.net c# and then run a command to get the status

i will then use the results to draw a report every 3 seconds and display it on my web page

this is the first time a have attempted this so i am rather ignorant

 private void connect_putty()
    {
        Process sh = new Process();
        sh.StartInfo.FileName = "Putty.exe";
        sh.StartInfo.UseShellExecute = false;
        sh.StartInfo.CreateNoWindow = false;
        sh.StartInfo.Arguments = "";
    }

what i presently have which to be honest is pathetic any help will be appreciated

Thanks in advance

Wolf
  • 170
  • 1
  • 4
  • 19
  • What exactly are you trying to get Putty to do? Connect to a remote host? – Adrian Wragg Jun 04 '14 at 11:48
  • Can you clarify if you want to connect to the server via SSH, or you actually want to launch putty and connect to a server? – Dane Balia Jun 04 '14 at 11:49
  • @adrian i usually run a command to get a status from a ip (yes the host)i then want to retieve the information and draw a graph which i will display on a web page – Wolf Jun 04 '14 at 11:50
  • @Dane to be honest i want to do everything from my c# code but i dont know if it is possible hence my attempt to launch putty if you know of a way il appreciate it – Wolf Jun 04 '14 at 11:51
  • 1
    It sounds like you want to connect to an SSH server, then execute a command, returning it's result and then graphing it. Ah! Then you need a C# OpenSSH API which will allow you to bypass Putty and speak to the server yourself – Dane Balia Jun 04 '14 at 11:51
  • @wolf What form does this status take? How would you retrieve this in a non-code manner? – Adrian Wragg Jun 04 '14 at 11:52
  • @dane i could kiss you(but i wont ) that is exactly what i want – Wolf Jun 04 '14 at 11:52
  • possible duplicate of [I'd like to run a command over ssh from a windows box running using c#](http://stackoverflow.com/questions/3642338/id-like-to-run-a-command-over-ssh-from-a-windows-box-running-using-c-sharp) – Adrian Wragg Jun 04 '14 at 11:53
  • @adrian it is statistics of active calls – Wolf Jun 04 '14 at 11:53
  • @Wolf Using PuTTY may be the wrong way to go about it; SSH.NET's been mentioned, but I think your question does amount to the same as the one I've just flagged. – Adrian Wragg Jun 04 '14 at 11:54
  • @Adrian you might be right il have a look ,i am beyond terrible with this type of coding il check out the flagged site – Wolf Jun 04 '14 at 11:56
  • Also possible duplicate of http://stackoverflow.com/questions/11169396/c-sharp-send-a-simple-ssh-command – Adrian Wragg Jun 04 '14 at 11:56
  • @dane hit the nail on the head with my wish and adrian like i said i have looked through a number of qeustions here on stack but i will study up on this all i need is the code to connect and run the command ,in a bit of a deadline so when i get off i will do a extensive study of this – Wolf Jun 04 '14 at 11:59

2 Answers2

2

I would suggest using Tamir.SSH. This will allow you to do everything from C#.

Also, I wrote some code once, it may help you.

https://github.com/daneb/Push2Linux/blob/master/Form1.cs

Sample:

 SshShell ssh; // create our shell

 ssh = new SshShell(aHost.host, aHost.username, aHost.password);

 // Command Output
  string commandoutput = string.Empty;

 // Remove Terminal Emulation Characters
  ssh.RemoveTerminalEmulationCharacters = true;

  // Connect to the remote server
  ssh.Connect();

  //Specify the character that denotes the end of response
  commandoutput = ssh.Expect(promptRegex);
Dane Balia
  • 5,271
  • 5
  • 32
  • 57
  • will i be able to get the results to update my graph for the site every 3 seconds ? – Wolf Jun 04 '14 at 12:09
1

PuTTY includes all the terminal emulation (hence the name), so assuming you mean 'connect via ssh', instead of the putty app specifically, then SSH.NET and SharpSSH are 2 good choices.

See this related question: C# send a simple SSH command

Community
  • 1
  • 1
James Manning
  • 13,429
  • 2
  • 40
  • 64