-
Notifications
You must be signed in to change notification settings - Fork 0
/
2. ConnectSftp.cs
38 lines (34 loc) · 1.21 KB
/
2. ConnectSftp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using BSS.Logging;
using Renci.SshNet;
using System;
#pragma warning disable CS8625
namespace CertBotHelper
{
internal static partial class Program
{
private static Boolean ConnectSftp(ref Configuration configuration, out SftpClient sftpClient)
{
try
{
sftpClient = new(configuration.CertBotIP, configuration.SSHUsername, new PrivateKeyFile(configuration.SSHPrivateKeyPath));
}
catch (Exception exception)
{
Log.FastLog($"Unable to create new SftpClient, invalid private key?\n{exception.Message}", LogSeverity.Critical, "SftpClient");
sftpClient = null;
return false;
}
try
{
sftpClient.Connect();
Log.FastLog($"Connected to " + configuration.CertBotIP, LogSeverity.Info, "SftpClient");
}
catch (Exception exception)
{
Log.FastLog($"Unable to connect to {configuration.CertBotIP}\n{exception.Message}", LogSeverity.Critical, "SftpClient");
return false;
}
return true;
}
}
}