summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Plugins/ValidationPlugins/Http/Sftp/Sftp.cs
blob: a7a88ee5b4648b62126241812926c15f92fd9396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using PKISharp.WACS.Clients;
using System.Linq;
using System.Threading.Tasks;

namespace PKISharp.WACS.Plugins.ValidationPlugins.Http
{
    internal class Sftp : HttpValidation<SftpOptions, Sftp>
    {
        private readonly 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 async Task DeleteFile(string path) => _sshFtpClient.Delete(path, SshFtpClient.FileType.File);

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

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

        protected override async Task WriteFile(string path, string content) => _sshFtpClient.Upload(path, content);
    }
}