Innovenergy_trunk/csharp/Lib/Utils/SshHost.cs

29 lines
803 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
using CliWrap;
using InnovEnergy.Lib.Utils.Net;
namespace InnovEnergy.Lib.Utils;
public class SshHost
{
private static Command Ssh { get; } = new Command("ssh");
public String HostName { get; }
public String User { get; }
public String? IdentityFile { get; }
public Command Command { get; }
public SshHost(String hostName, String? user = null, String? identityFile = null)
{
HostName = hostName;
User = user ?? "root";
IdentityFile = identityFile;
var identity = identityFile is not null
? $" -i {identityFile}"
: "";
Command = Ssh.WithArguments($"{User}@{HostName}{identity}");
}
public Task<Boolean> Ping() => HostName.Ping();
}