示例#1
0
        private static string FtpDownLoad(string filePath, string fileNameRtofs, DateTime dateNextRtofsForecastFileToGet)
        {
            string localFilePath = "";

            // Ftp Check and Download
            using (FtpClient conn = new FtpClient())
            {
                //ms
                conn.SocketPollInterval           = 1000;
                conn.ConnectTimeout               = 30000;
                conn.ReadTimeout                  = 300000;
                conn.DataConnectionConnectTimeout = 300000;
                conn.DataConnectionReadTimeout    = 300000;

                conn.Host        = "ftp.ncep.noaa.gov";
                conn.Credentials = new NetworkCredential(_ftpAccountId, _ftpAccountPw);
                conn.Connect();

                var checkPoint = 0;

                if (conn.FileExists(filePath))
                {
                    var ftpNww3DownloadCheck = new FTP_RAWDATA_DOWNLOAD_CHECK();
                    var oceanJobList         = new JOB_LIST_OCEAN_WEATHER();

                    Progress <double> progress = new Progress <double>(x =>
                    {
                        if (x < 0)
                        {
                        }
                        if (x > checkPoint)
                        {
                            checkPoint = checkPoint + 10;

                            _log.Info($"{dateNextRtofsForecastFileToGet.ToString("yyyy-MM-dd mm-HH")} / {filePath}   Progres : {Math.Round(x, 0)} % ");
                        }
                    });

                    localFilePath = Environment.ExpandEnvironmentVariables(@"%HOME%\decode\rtofsForecast\");
                    localFilePath = Path.Combine(localFilePath, dateNextRtofsForecastFileToGet.Year.ToString("0000"), dateNextRtofsForecastFileToGet.Month.ToString("00"), dateNextRtofsForecastFileToGet.Day.ToString("00"), fileNameRtofs);

                    Directory.CreateDirectory(Path.GetDirectoryName(localFilePath));
                    //localFilePath = Path.Combine(localFilePath, fileNameRtofs);
                    conn.DownloadFile(@localFilePath, filePath, true, FtpVerify.Retry, progress);
                    _log.Info($"{dateNextRtofsForecastFileToGet.ToString("yyyy-MM-dd mm-HH")} / {filePath}  Progres : Complete");
                    _log.Info($"===============================================================================================================");
                    conn.Disconnect();
                    return(localFilePath);
                }
                else
                {
                    return("false");
                }
            }
        }
示例#2
0
        private static void FtpDownLoad()
        {
            // Retrieve the storage account
            CloudBlobContainer container = _blobClient.GetContainerReference("gfs");

            // Ftp Check and Download
            using (FtpClient conn = new FtpClient())
            {
                conn.SocketPollInterval           = 1000;
                conn.ConnectTimeout               = 30000;
                conn.ReadTimeout                  = 300000;
                conn.DataConnectionConnectTimeout = 300000;
                conn.DataConnectionReadTimeout    = 300000;

                conn.Host        = "ftp.ncep.noaa.gov";
                conn.Credentials = new NetworkCredential(_ftpAccountId, _ftpAccountPw);
                conn.Connect();

                foreach (var item in _fileListToNeedDownload)
                {
                    var checkPoint = 0;

                    if (conn.FileExists(item[4]))
                    {
                        var ftpDownloadCheck       = new FTP_RAWDATA_DOWNLOAD_CHECK();
                        var oceanJobList           = new JOB_LIST_OCEAN_WEATHER();
                        var blobFullPath           = Path.Combine(item[0], item[1], item[2], item[5]);
                        Progress <double> progress = new Progress <double>(x =>
                        {
                            // When progress in unknown, -1 will be sent
                            if (x < 0)
                            {
                            }
                            if (x > checkPoint)
                            {
                                checkPoint = checkPoint + 10;

                                _log.Info($"{item[0]}-{item[1]}-{item[2]} {item[3]}:00 / {item[5]}   Progres : {Math.Round(x, 0)} % ");
                            }
                        });

                        conn.RetryAttempts               = 3;
                        ftpDownloadCheck.DATE_OF_FILE    = new DateTime(Convert.ToInt32(item[0]), Convert.ToInt32(item[1]), Convert.ToInt32(item[2]), 0, 0, 0);
                        ftpDownloadCheck.FILE_TYPE       = "GFS";
                        ftpDownloadCheck.FILE_PATH       = item[5];
                        ftpDownloadCheck.TIME_DOWNLOADED = DateTime.UtcNow;

                        MemoryStream streamFmFtp = new MemoryStream();
                        conn.Download(streamFmFtp, item[4], progress);

                        _log.Info($"{item[0]}-{item[1]}-{item[2]} {item[3]}:00 / {item[5]}   Progres : Complete");
                        _log.Info($"========================================================================================================");

                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobFullPath);
                        streamFmFtp.Position = 0;
                        using (var fileStream = streamFmFtp)
                        {
                            blockBlob.UploadFromStream(streamFmFtp);
                        }
                        _oceanModel.FTP_RAWDATA_DOWNLOAD_CHECK.Add(ftpDownloadCheck);
                        _oceanModel.SaveChanges();

                        oceanJobList.DATE_OF_JOB_TRIGGERED = DateTime.UtcNow;                         //job을 등록한 시각
                        oceanJobList.JOB_TYPE = "GFS_DECODE";                                         //job 종류
                        oceanJobList.DATE_OF_COMPLETE_JOB_TIME = new DateTime(2000, 01, 01, 0, 0, 0); //job 완료시간
                        oceanJobList.IS_COMPLETE_JOB           = false;                               // job 수행여부
                        oceanJobList.REASON_OF_NOT_COMPLETE    = "not started";                       // job이 수행되지 않은 이유

                        oceanJobList.FILE_PATH = blobFullPath;                                        // blobpath
                        _logModel.JOB_LIST_OCEAN_WEATHER.Add(oceanJobList);
                        _logModel.SaveChanges();
                    }
                }
                conn.Disconnect();
            }
        }
示例#3
0
        private static void FtpDownLoad()
        {
            CloudBlobContainer container = _blobClient.GetContainerReference("rtofs");

            // Ftp Check and Download
            using (FtpClient conn = new FtpClient())
            {
                //ms
                conn.SocketPollInterval           = 1000;
                conn.ConnectTimeout               = 30000;
                conn.ReadTimeout                  = 300000;
                conn.DataConnectionConnectTimeout = 300000;
                conn.DataConnectionReadTimeout    = 300000;

                conn.Host        = "ftp.ncep.noaa.gov";
                conn.Credentials = new NetworkCredential(_ftpAccountId, _ftpAccountPw);
                conn.Connect();

                foreach (var item in _fileListToNeedDownload)
                {
                    var checkPoint = 0;

                    if (conn.FileExists(item[4]))
                    {
                        var ftpNww3DownloadCheck = new FTP_RAWDATA_DOWNLOAD_CHECK();
                        var oceanJobList         = new JOB_LIST_OCEAN_WEATHER();

                        var blobFullPath           = Path.Combine(item[0], item[1], item[2], item[5]);
                        Progress <double> progress = new Progress <double>(x =>
                        {
                            if (x < 0)
                            {
                            }
                            if (x > checkPoint)
                            {
                                checkPoint = checkPoint + 5;

                                _log.Info($"{item[0]}-{item[1]}-{item[2]} {item[3]}:00 / {item[5]}   Progres : {Math.Round(x, 0)} % ");
                            }
                        });

                        conn.RetryAttempts = 3;
                        var dateOfFile = new DateTime(Convert.ToInt16(item[0]), Convert.ToInt16(item[1]), Convert.ToInt16(item[2]), 0, 0, 0);
                        ftpNww3DownloadCheck.DATE_OF_FILE    = dateOfFile;
                        ftpNww3DownloadCheck.FILE_TYPE       = "RTOFS";
                        ftpNww3DownloadCheck.FILE_PATH       = item[5];
                        ftpNww3DownloadCheck.TIME_DOWNLOADED = DateTime.UtcNow;

                        MemoryStream streamFmFtp = new MemoryStream();
                        conn.Download(streamFmFtp, item[4], progress);
                        _log.Info($"{item[0]}-{item[1]}-{item[2]} {item[3]}:00 / {item[5]}   Progres : Complete");
                        _log.Info($"===============================================================================================================");

                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobFullPath);
                        streamFmFtp.Position = 0;
                        using (var fileStream = streamFmFtp)
                        {
                            blockBlob.UploadFromStream(streamFmFtp);
                        }
                        _oceanModel.FTP_RAWDATA_DOWNLOAD_CHECK.Add(ftpNww3DownloadCheck);
                        _oceanModel.SaveChanges();

                        var fileNameOfDiagOrProg = "";

                        if (item[5].Contains("diag"))
                        {
                            fileNameOfDiagOrProg = item[5].Replace("diag", "prog");
                        }

                        if (item[5].Contains("prog"))
                        {
                            fileNameOfDiagOrProg = item[5].Replace("prog", "diag");
                        }

                        var checkDiagData = _oceanModel.FTP_RAWDATA_DOWNLOAD_CHECK.Where(d => d.FILE_TYPE == "RTOFS" && d.DATE_OF_FILE == dateOfFile && d.FILE_PATH == fileNameOfDiagOrProg).Count();
                        if (checkDiagData > 0)
                        {
                            oceanJobList.DATE_OF_JOB_TRIGGERED = DateTime.UtcNow;
                            oceanJobList.JOB_TYPE = "RTOFS_DECODE";
                            oceanJobList.DATE_OF_COMPLETE_JOB_TIME = new DateTime(2000, 01, 01, 0, 0, 0);
                            oceanJobList.IS_COMPLETE_JOB           = false;
                            oceanJobList.REASON_OF_NOT_COMPLETE    = "not started";

                            oceanJobList.FILE_PATH = blobFullPath;
                            _logModel.JOB_LIST_OCEAN_WEATHER.Add(oceanJobList);
                            _logModel.SaveChanges();
                        }
                    }
                }
                conn.Disconnect();
            }
        }