3

I am trying to run a UNIX command on remote host from my C# application.

I have seen various post over internet including SO for doing this using various libraries like SmartSsh any many others. And some others using command line commands.

I do not want to use any third party library.

Hence I tried using TcpClient class with example shown here on MSDN. I am passing hostname as : user@servername and port 22. When I run this code it trows an exception

SocketException (0x80004005): No such host is known
at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port) 

Is it because my server/host expect a password for user, if yes then how do I provide that?

5
  • I tried searching existing questions like this but could not reach to right one. If this is a duplicate please redirect me to correct place. Thanks. Commented Dec 15, 2011 at 7:07
  • 3
    A socket is only about a connection, see it as calling a person over the phone. The socket makes sure you have a conncetion with the other person but you still need a language (protocol) to communicate. Over the phone, that is a common language. When you want to execute unix commands you also need a language that both the you and the target understand. One of those protocols is SSH, port 22. SSH also defines authentication, so you need to implement the SSH protocol or better, use a 3th party library to do that for you Commented Dec 15, 2011 at 7:13
  • @Polity : Thanks for such a good explanation of what I was missing and that too in simplest language. Commented Dec 15, 2011 at 7:52
  • @Polity I would like to mark your comment as answer to my problem. Commented Dec 15, 2011 at 8:04
  • Thanks :) i posted my comment as an answer Commented Dec 15, 2011 at 8:06

1 Answer 1

2

A socket is only about a connection, see it as calling a person over the phone. The socket makes sure you have a conncetion with the other person but you still need a language (protocol) to communicate. Over the phone, that is a common language. When you want to execute unix commands you also need a language that both the you and the target understand. One of those protocols is SSH, port 22. SSH also defines authentication, so you need to implement the SSH protocol or better, use a 3th party library to do that for you

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please suggest very light weight .net library for this task. I only want to run some very simple UNIX command, so I don't need a very big has-all tool.
Just google around a bit, i found codeproject.com/KB/IP/sharpssh.aspx and routrek.co.jp/en/product/varaterm/granados.html both free and simple.

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.