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

13
  • What exactly are you trying to get Putty to do? Connect to a remote host? Commented Jun 4, 2014 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? Commented Jun 4, 2014 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 Commented Jun 4, 2014 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 Commented Jun 4, 2014 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 Commented Jun 4, 2014 at 11:51

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

will i be able to get the results to update my graph for the site every 3 seconds ?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.