コード例 #1
0
        private void DownloadEpgPackage(string archiveDirectory, string localDownloadDirectory)
        {
            SftpTransferOperationResult = false;
            var localfile    = Path.Combine(localDownloadDirectory, LatestEpgPackage.Name);
            var archivedFile = Path.Combine(archiveDirectory, LatestEpgPackage.Name);

            if (System.IO.File.Exists(localfile) || System.IO.File.Exists(archivedFile))
            {
                Console.WriteLine($"Epg file: {LatestEpgPackage.Name} has previously been downloaded.");
            }
            else
            {
                Console.WriteLine($"Downloading Latest EPG File: {LatestEpgPackage.Name} to {localDownloadDirectory}");
                var operationResult = SftpSession.GetFiles(RemotePath.EscapeFileMask(LatestEpgPackage.FullName), localDownloadDirectory);

                if (operationResult.IsSuccess)
                {
                    Console.WriteLine($"Remote File: {LatestEpgPackage.FullName} Downloaded successfully");
                    EpgTarBall = new FileInfo(localfile);
                    SftpTransferOperationResult = true;
                }
                else
                {
                    throw new Exception($"Failed to download file: {operationResult.Failures[0]}");
                }
            }
        }