From 5a663143c92215262f02aa40eae9b36b32c26ff2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 27 Jun 2021 12:05:52 -0500 Subject: stub FTPService --- src/slskd/Integrations/FTP/FTPService.cs | 61 +++++++++++++++++++++++++++++++ src/slskd/Integrations/FTP/IFTPService.cs | 26 +++++++++++++ src/slskd/Startup.cs | 2 + 3 files changed, 89 insertions(+) create mode 100644 src/slskd/Integrations/FTP/FTPService.cs create mode 100644 src/slskd/Integrations/FTP/IFTPService.cs (limited to 'src') diff --git a/src/slskd/Integrations/FTP/FTPService.cs b/src/slskd/Integrations/FTP/FTPService.cs new file mode 100644 index 00000000..b704063c --- /dev/null +++ b/src/slskd/Integrations/FTP/FTPService.cs @@ -0,0 +1,61 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Integrations.FTP +{ + using System; + using System.Threading.Tasks; + using FluentFTP; + using Microsoft.Extensions.Logging; + using static slskd.Options.IntegrationOptions; + + public class FTPService : IFTPService + { + public FTPService( + Microsoft.Extensions.Options.IOptionsMonitor optionsMonitor, + ILogger log) + { + Options = optionsMonitor.CurrentValue; + Log = log; + + FtpEncryptionMode encryptionMode; + + 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); + } + + Client = new FtpClient(FTPOptions.Address, FTPOptions.Port, FTPOptions.Username, FTPOptions.Password); + Client.EncryptionMode = encryptionMode; + } + + private Options Options { get; } + private FTPOptions FTPOptions => Options.Integration.FTP; + private ILogger Log { get; set; } + private FtpClient Client { get; set; } + + public Task UploadAsync(string filename) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/slskd/Integrations/FTP/IFTPService.cs b/src/slskd/Integrations/FTP/IFTPService.cs new file mode 100644 index 00000000..11c12073 --- /dev/null +++ b/src/slskd/Integrations/FTP/IFTPService.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Integrations.FTP +{ + using System.Threading.Tasks; + + public interface IFTPService + { + Task UploadAsync(string filename); + } +} diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index dd44fd87..ddf2f637 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -35,6 +35,7 @@ namespace slskd using Serilog; using slskd.Authentication; using slskd.Cryptography; + using slskd.Integrations.FTP; using slskd.Management; using slskd.Messaging; using slskd.Peer; @@ -186,6 +187,7 @@ namespace slskd services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddHostedService(); services.AddSingleton(_ => Service.SoulseekClient); -- cgit v1.2.3