Skip to content

Instantly share code, notes, and snippets.

@TristanOrta
Created May 17, 2023 16:14
Show Gist options
  • Save TristanOrta/b752446b9c667553e9e32c986ce560ef to your computer and use it in GitHub Desktop.
Save TristanOrta/b752446b9c667553e9e32c986ce560ef to your computer and use it in GitHub Desktop.
simple example of an SSH connection using the SSH.NET library
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.Text;
namespace ssh_CShP
{
class ConexionSSH
{
public string conectSSH()
{
string host, user, pass, ComandResult;
host = "127.0.0.1";
user = "user";
pass = "Pass";
try
{
SshClient sshclient = new SshClient(host, user, pass);
sshclient.Connect();
SshCommand sc = sshclient.CreateCommand("ls -la");
sc.Execute();
ComandResult = sc.Result;
sshclient.Disconnect();
}
catch (Exception e)
{
ComandResult = Convert.ToString(e);
}
return ComandResult;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment