summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Plugins/ValidationPlugins/Http/Sftp/Sftp.cs
blob: 150a3c03657b91fab2cefd60264293dd7c79d1f6 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
using PKISharp.WACS.Clients;
using System.Linq;

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)
        {
            return !_sshFtpClient.GetFiles(path).Any();
        }

        protected override void WriteFile(string path, string content)
        {
            _sshFtpClient.Upload(path, content);
        }

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