Created
May 17, 2023 16:14
-
-
Save TristanOrta/b752446b9c667553e9e32c986ce560ef to your computer and use it in GitHub Desktop.
simple example of an SSH connection using the SSH.NET library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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