33 lines
953 B
C#
33 lines
953 B
C#
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();
|
|
|
|
public static implicit operator SshHost(String hostname) => new SshHost(hostname);
|
|
|
|
public override String ToString() => Command.ToString();
|
|
} |