aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Integrations/FTP/FTPClientFactory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Integrations/FTP/FTPClientFactory.cs')
-rw-r--r--src/slskd/Integrations/FTP/FTPClientFactory.cs38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/slskd/Integrations/FTP/FTPClientFactory.cs b/src/slskd/Integrations/FTP/FTPClientFactory.cs
index cc076ca1..e9ee0721 100644
--- a/src/slskd/Integrations/FTP/FTPClientFactory.cs
+++ b/src/slskd/Integrations/FTP/FTPClientFactory.cs
@@ -15,6 +15,8 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
+using Microsoft.Extensions.Options;
+
namespace slskd.Integrations.FTP
{
using System;
@@ -30,25 +32,13 @@ namespace slskd.Integrations.FTP
/// Initializes a new instance of the <see cref="FTPClientFactory"/> class.
/// </summary>
/// <param name="optionsMonitor">The options monitor used to derive application options.</param>
- public FTPClientFactory(Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor)
+ public FTPClientFactory(IOptionsMonitor<Options> optionsMonitor)
{
- Options = optionsMonitor.CurrentValue;
-
- try
- {
- EncryptionMode = (FtpEncryptionMode)Enum.Parse(typeof(FtpEncryptionMode), FTPOptions.EncryptionMode, ignoreCase: true);
- }
- catch (Exception ex)
- {
- // Options should validate that the given string is parsable to FtpEncryptionMode through EnumAttribute; if this
- // throws there's a bug somewhere.
- throw new ArgumentException($"Failed to parse {typeof(FtpEncryptionMode).Name} from application Options. This is most likely a programming error; please file a GitHub issue and include your FTP configuration.", ex);
- }
+ OptionsMonitor = optionsMonitor;
}
- private FtpEncryptionMode EncryptionMode { get; set; }
- private FTPOptions FTPOptions => Options.Integration.FTP;
- private Options Options { get; set; }
+ private FTPOptions FTPOptions => OptionsMonitor.CurrentValue.Integration.FTP;
+ private IOptionsMonitor<Options> OptionsMonitor { get; set; }
/// <summary>
/// Creates an instance of <see cref="FtpClient"/>.
@@ -57,10 +47,24 @@ namespace slskd.Integrations.FTP
public FtpClient CreateFtpClient()
{
var client = new FtpClient(FTPOptions.Address, FTPOptions.Port, FTPOptions.Username, FTPOptions.Password);
- client.EncryptionMode = EncryptionMode;
+ client.EncryptionMode = ParseFtpEncryptionMode(FTPOptions.EncryptionMode);
client.ValidateAnyCertificate = FTPOptions.IgnoreCertificateErrors;
return client;
}
+
+ private FtpEncryptionMode ParseFtpEncryptionMode(string encryptionMode)
+ {
+ try
+ {
+ return (FtpEncryptionMode)Enum.Parse(typeof(FtpEncryptionMode), encryptionMode, ignoreCase: true);
+ }
+ catch (Exception ex)
+ {
+ // Options should validate that the given string is parsable to FtpEncryptionMode through EnumAttribute; if this
+ // throws there's a bug somewhere.
+ throw new ArgumentException($"Failed to parse {typeof(FtpEncryptionMode).Name} from application Options. This is most likely a programming error; please file a GitHub issue and include your FTP configuration.", ex);
+ }
+ }
}
} \ No newline at end of file