Esempio n. 1
0
        public static async Task RetrieveSFTPFilesAsync(string configFileName)
        {
            SFTP_Config rootConfigVariable = readInRootConfigurations(configFileName);

            using (SftpClient sftp = new SftpClient(rootConfigVariable.SFTP_Host, rootConfigVariable.SFTP_User, rootConfigVariable.SFTP_Password))
            {
                DirectorySource DirSRC = new DirectorySource();
                try
                {
                    sftp.Connect();

                    //Download Subdirectory flag.
                    bool recursiveDownload = true;

                    // Start download of the directory
                    await DownloadDirectoryAsync(
                        sftp,
                        rootConfigVariable.ImportDirectory,
                        DirSRC.SRC_Directory,
                        recursiveDownload
                        );

                    sftp.Disconnect();
                }
                catch (Exception er)
                {
                    System.ArgumentException argEx = new System.ArgumentException($"Could Not Connect To {rootConfigVariable.SFTP_Host}.");
                    throw argEx;
                }
            }
        }
Esempio n. 2
0
        public static SFTP_Config readInRootConfigurations(string configFileName)
        {
            DirectorySource DirSRC  = new DirectorySource();
            SFTP_Config     SFTPCFG = new SFTP_Config();
            XmlDocument     doc     = new XmlDocument();

            doc.Load(configFileName);

            SFTPCFG.IsSFTP = doc.DocumentElement.SelectSingleNode("IsSFTP").InnerText;
            if (SFTPCFG.IsSFTP == "True")
            {
                SFTPCFG.SFTP_User       = doc.DocumentElement.SelectSingleNode("SFTP_Username").InnerText;
                SFTPCFG.SFTP_Password   = doc.DocumentElement.SelectSingleNode("SFTP_Password").InnerText;
                SFTPCFG.SFTP_Host       = doc.DocumentElement.SelectSingleNode("SFTP_Host").InnerText;
                SFTPCFG.ImportDirectory = doc.DocumentElement.SelectSingleNode("ImportDirectory").InnerText;
            }
            if (SFTPCFG.IsSFTP == "False")
            {
                SFTPCFG.ImportDirectory = doc.DocumentElement.SelectSingleNode("ImportDirectory").InnerText;
            }


            return(SFTPCFG);
        }