Files
NetPanel/NetPanel.Bl/SshBl.cs
2023-11-08 17:43:39 +08:00

54 lines
1.2 KiB
C#

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();
}
}
}