summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Plugins/ValidationPlugins/Http/Sftp/Sftp.cs
blob: f3f536cd76e86dfe6b1f280d21096184ede034dd (plain)
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
using PKISharp.WACS.Clients;
using System.Linq;
using System.Threading.Tasks;

namespace PKISharp.WACS.Plugins.ValidationPlugins.Http
{
    internal class Sftp : HttpValidation<SftpOptions, Sftp>
    {
        private SshFtpClient? _sshFtpClient;

        public Sftp(SftpOptions options, HttpValidationParameters pars, RunLevel runLevel) : base(options, runLevel, pars) => _sshFtpClient = new SshFtpClient(_options.Credential.GetCredential(), pars.LogService);

        protected override char PathSeparator => '/';

        protected override void DeleteFile(string path) => _sshFtpClient.Delete(path, SshFtpClient.FileType.File);

        protected override void DeleteFolder(string path) => _sshFtpClient.Delete(path, SshFtpClient.FileType.Directory);

        protected override bool IsEmpty(string path) => !_sshFtpClient.GetFiles(path).Any();

        protected override void WriteFile(string path, string content) => _sshFtpClient.Upload(path, content);

        public override Task CleanUp()
        {
            base.CleanUp();
            // Switched setting this to null, since this class will be needed for deleting files and folder structure
            _sshFtpClient = null;
            return Task.CompletedTask;
        }
    }
}