123
This commit is contained in:
@@ -14,6 +14,7 @@ namespace NetPanel.Bl
|
||||
|
||||
public static string Exec(string fileName,string command)
|
||||
{
|
||||
|
||||
|
||||
if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows
|
||||
{
|
||||
|
||||
@@ -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
53
NetPanel.Bl/SshBl.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user