Home » x Other Posts » Remote server connection by SSH using C#

Remote server connection by SSH using C#

SSH is a secure network protocol to use remote shell services or execute commands. You can connect to a remote server by SSH on Visual Studio. To do this, you need a SSH library. My suggestion is SharpSSH.

Download DLL files from SourceForge. You should add these DLL files to your Visual Studio project:

  • DiffieHellman.dll
  • Org.Mentalis.Security.dll
  • Tamir.SharpSSH.dll

To connect to server and execute commands, code is here:

SshExec shell = new SshExec(hostIP, username);
shell.Password = password;
string output = shell.RunCommand(command);

My SSH application is below. It is a simple SSH Command Prompt.

SSH Command Prompt
SSH Command Prompt

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

7 thoughts on “Remote server connection by SSH using C#”

  1. I look the look of your application, and I looks just like what I require.

    Just wondering if you are will to save me some time and effort and share the source

  2. this is good a description but i coudnt use this dll.İ am working sinde 2 days but, it connected yet. i a get an error as follows:

    Tamir.SharpSsh.jsch.JSchException: System.Net.Sockets.SocketException: The reque
    sted name is valid, but no data of the requested type was found
    at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)

    at System.Net.Dns.GetHostByName(String hostName)
    at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
    at Tamir.SharpSsh.jsch.Util.createSocket(String host, Int32 port, Int32 timeo
    at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
    at Tamir.SharpSsh.jsch.Session.connect()
    at Tamir.SharpSsh.SshBase.ConnectSession(Int32 tcpPort)
    at Tamir.SharpSsh.SshBase.Connect(Int32 tcpPort)
    at Test_sftp.Program.Main(String[] args) in ….

    thanks, good working.


Leave a Comment