This commit is contained in:
Mn
2023-11-08 17:43:39 +08:00
parent efaed011e0
commit b626dc1b68
5 changed files with 213 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ namespace NetPanel.Bl
public static string Exec(string fileName,string command)
{
if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows
{

View File

@@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SSH.NET" Version="2023.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetPanel.Entity\NetPanel.Entity.csproj" />
<ProjectReference Include="..\NetPanel.Help\NetPanel.Help.csproj" />

53
NetPanel.Bl/SshBl.cs Normal file
View File

@@ -0,0 +1,53 @@
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
namespace NetPanel.Bl
{
public class SshBl
{
private string _username = "";
private string _pwd = "";
private string _host = "";
private SshClient client = null;
public SshBl(string host, string username, string pwd)
{
_username = username;
_pwd = pwd;
_host = host;
client = new SshClient(host, username, pwd);
client.Connect();
}
public StreamReader RunCommand(string command)
{
var sshCommand = client.CreateCommand(command);
var asyncExecute = sshCommand.BeginExecute();
return new StreamReader(sshCommand.OutputStream);
//string outStr;
//while ((outStr = reader.ReadLine()) != null)
//{
//}
}
/// <summary>
/// 关闭
/// </summary>
public void Dispose()
{
client.Disconnect();
client.Dispose();
}
}
}