-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Renci.SshNet; | ||
|
||
namespace CustomShell | ||
{ | ||
class SSHClient | ||
{ | ||
SshClient client; | ||
public SSHClient() | ||
{ | ||
|
||
} | ||
|
||
public void EstablishConnection(string host, string username, string password) | ||
{ | ||
try | ||
{ | ||
ConnectionInfo connInfo = new ConnectionInfo(host, username, new PasswordAuthenticationMethod(username, password), new PrivateKeyAuthenticationMethod("rsa.key")); | ||
client = new SshClient(connInfo); | ||
client.Connect(); | ||
MainController.controller.AddTextToConsole("Successfully connected to the host..."); | ||
MainController.controller.inputBox.Text = MainController.controller.InputPrefix(); | ||
MainController.controller.inputBox.SelectionStart = MainController.controller.inputBox.Text.Length; | ||
} | ||
catch (Exception) | ||
{ | ||
MainController.controller.AddTextToConsole("Could not connect, did you enter the right login credentials?"); | ||
return; | ||
} | ||
} | ||
|
||
public void SendCommand(string command) | ||
{ | ||
try | ||
{ | ||
SshCommand result = client.RunCommand(command); | ||
MainController.controller.AddCommandToConsole(MainController.controller.tokens); | ||
|
||
//Add a red color for the ssh output | ||
MainController.controller.AddTextToConsole(result.Result); | ||
MainController.controller.outputBox.Select(MainController.controller.outputBox.Text.Length - result.Result.Length - 1, MainController.controller.outputBox.Text.Length); | ||
MainController.controller.outputBox.SelectionColor = Color.Red; | ||
MainController.controller.outputBox.SelectionStart = MainController.controller.outputBox.Text.Length; | ||
|
||
MainController.controller.inputBox.Text = MainController.controller.InputPrefix(); | ||
MainController.controller.inputBox.SelectionStart = MainController.controller.inputBox.Text.Length; | ||
} | ||
catch (Exception) | ||
{ | ||
MainController.controller.AddTextToConsole("Could not execute command..."); | ||
return; | ||
} | ||
} | ||
|
||
public void TerminateConnection() | ||
{ | ||
try | ||
{ | ||
client.Disconnect(); | ||
MainController.controller.AddTextToConsole("Successfully terminated the connection..."); | ||
MainController.controller.inputBox.Text = MainController.controller.InputPrefix(); | ||
MainController.controller.inputBox.SelectionStart = MainController.controller.inputBox.Text.Length; | ||
} | ||
catch (Exception) | ||
{ | ||
MainController.controller.AddTextToConsole("Could not terminate..."); | ||
return; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FluentFTP" version="34.0.0" targetFramework="net472" /> | ||
<package id="SSH.NET" version="2020.0.1" targetFramework="net472" /> | ||
</packages> |