Exemple #1
0
        private List <string> GetGeoTiffFiles()
        {
            // Example string: ftp://13.78.149.101:21/2018/08/15
            string        url        = FileServerUtil.GetFileServerUrl("13.78.149.101", 21, new DateTime(2018, 8, 15));
            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(url);

            ftpRequest.Method      = WebRequestMethods.Ftp.ListDirectory;
            ftpRequest.Credentials = FileServerUtil.GetFileServerCredential();

            FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

            string[] directoryOrFileNames;
            using (Stream responseStream = ftpResponse.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                string       result = reader.ReadToEnd();
                directoryOrFileNames = String.IsNullOrEmpty(result) ? null : result.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            }

            List <string> filteredResult = new List <string>();

            for (int i = 0; i < directoryOrFileNames.Length; i++)
            {
                string fileName = directoryOrFileNames[i];
                if (fileName.Contains("_230000.p") && fileName.EndsWith(".tif"))
                {
                    filteredResult.Add(string.Format("{0}/{1}", url, fileName));
                }
            }

            return(filteredResult);
        }
Exemple #2
0
        public void DownloadAndSaveFiles()
        {
            // Example string: ftp://13.78.149.101:21/subset
            string        serverUrl  = FileServerUtil.GetFileServerUrl("13.78.149.101", 21, "subset");
            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(serverUrl);

            ftpRequest.Method      = WebRequestMethods.Ftp.ListDirectory;
            ftpRequest.Credentials = FileServerUtil.GetFileServerCredential();

            FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();

            string[] directoryOrFileNames;
            using (Stream responseStream = ftpResponse.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream);
                string       result = reader.ReadToEnd();
                directoryOrFileNames = String.IsNullOrEmpty(result) ? null : result.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            }

            List <string> filteredResult = new List <string>();

            for (int i = 0; i < directoryOrFileNames.Length; i++)
            {
                string fileName = directoryOrFileNames[i];
                if (fileName.EndsWith(".zip"))
                {
                    string serverFileFullPath = string.Format("{0}/{1}", serverUrl, fileName);
                    FileServerUtil.ProcessSourceFileFromFTPServer(serverFileFullPath, @"C:\GmuTemp");
                }
            }
        }