/DetailedCareyLoading
Created 1 year, 7 months ago...
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
using Renci.SshNet;
using System;
using System.IO;
namespace DiscordBotController
{
public class SSHManager
{
private string botIp;
private string botUsername;
private string password; // Add password field
private SshClient client;
public SSHManager(string ip, string username, string password)
{
botIp = ip;
botUsername = username;
this.password = password; // Assign the password
client = new SshClient(botIp, botUsername, this.password); // Pass the password to the constructor
}
// ... Other methods ...
public void StartBotService(Action<string> outputCallback)
{
try
{
outputCallback("Connecting to SSH...");
client.Connect();
outputCallback("Connected to SSH.");
var command = client.RunCommand("sudo systemctl start bub.service");
outputCallback("Command output: " + command.Result);
}
catch (Exception ex)
{
outputCallback("An error occurred: " + ex.Message);
}
finally
{
outputCallback("Disconnecting from SSH...");
client.Disconnect();
outputCallback("Disconnected from SSH.");
}
}
public void StopBotService(Action<string> outputCallback)
{
try
{
outputCallback("Connecting to SSH...");
client.Connect();
outputCallback("Connected to SSH.");
var command = client.RunCommand("sudo systemctl stop bub.service");
outputCallback("Command output: " + command.Result);
}
catch (Exception ex)
{
outputCallback("An error occurred: " + ex.Message);
}
finally
{
outputCallback("Disconnecting from SSH...");
client.Disconnect();
outputCallback("Disconnected from SSH.");
}
}
}
}