-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4. DownloadCertificates.cs
41 lines (37 loc) · 2.01 KB
/
4. DownloadCertificates.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
39
40
41
using BSS.Logging;
using Renci.SshNet;
using System;
using System.IO;
namespace CertBotHelper
{
internal static partial class Program
{
private static Boolean DownloadCertificates(SftpClient sftpClient, ref Configuration configuration)
{
try
{
using (FileStream fileStream = File.Open(Path.Combine(configuration.LocalCertificateOutputPath, "cert.crt"), FileMode.Create, FileAccess.Write, FileShare.Write))
{
sftpClient.DownloadFile(configuration.RemoteCertBotPath + "cert.crt", fileStream);
}
Log.FastLog($"Placed cert.crt in: " + Path.Combine(configuration.LocalCertificateOutputPath, "cert.crt"), LogSeverity.Info, "Download");
using (FileStream fileStream = File.Open(Path.Combine(configuration.LocalCertificateOutputPath, "chain.crt"), FileMode.Create, FileAccess.Write, FileShare.Write))
{
sftpClient.DownloadFile(configuration.RemoteCertBotPath + "chain.crt", fileStream);
}
Log.FastLog($"Placed cert.crt in: " + Path.Combine(configuration.LocalCertificateOutputPath, "chain.crt"), LogSeverity.Info, "Download");
using (FileStream fileStream = File.Open(Path.Combine(configuration.LocalCertificateOutputPath, "fullChain.crt"), FileMode.Create, FileAccess.Write, FileShare.Write))
{
sftpClient.DownloadFile(configuration.RemoteCertBotPath + "fullChain.crt", fileStream);
}
Log.FastLog($"Placed cert.crt in: " + Path.Combine(configuration.LocalCertificateOutputPath, "fullChain.crt"), LogSeverity.Info, "Download");
}
catch (Exception exception)
{
Log.FastLog($"An error occurred whilst downloading the certificates\n{exception.Message}", LogSeverity.Critical, "Download");
return false;
}
return true;
}
}
}