public void ProcessSourceFileFromFTPServer(string serverFilePath, string savedDirectory) { string fileName = Path.GetFileName(serverFilePath); string tempFilePath = Path.GetTempPath(); // Download zip file to temp folder string tempFileName = Path.Combine(tempFilePath, fileName); FtpUtil.DownloadAndSaveFile(serverFilePath, tempFileName); // Unzip downloaded zip file string unCompressFolder = Path.Combine(tempFilePath, "uncompress"); if (Directory.Exists(unCompressFolder)) { Directory.Delete(unCompressFolder, true); } Directory.CreateDirectory(unCompressFolder); ZipFile.ExtractToDirectory(tempFileName, unCompressFolder); // Delete downloaded zip file File.Delete(tempFileName); string[] kmlFileNames = Directory.GetFiles(unCompressFolder, "*.kml"); for (int i = 0; i < kmlFileNames.Length; i++) { // cspp-viirs-flood-globally_20180815_010000_54.kml string name = Path.GetFileNameWithoutExtension(kmlFileNames[i]); string directoryName = Path.GetDirectoryName(kmlFileNames[i]); string[] elements = name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); if (elements.Length != 4) { // 0: cspp-viirs-flood-globally, 1: 20180815_010000_54, 2: 010000, 3: 54 throw new Exception(); } string folderPath = Path.Combine(savedDirectory, elements[1].Substring(0, 4), elements[1].Substring(4, 2), elements[1].Substring(6, 2)); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string disfolderPath = Path.Combine(folderPath, "dis"); if (!Directory.Exists(disfolderPath)) { Directory.CreateDirectory(disfolderPath); } string rawfolderPath = Path.Combine(folderPath, "raw"); if (!Directory.Exists(rawfolderPath)) { Directory.CreateDirectory(rawfolderPath); } string unifolderPath = Path.Combine(folderPath, "uni"); if (!Directory.Exists(unifolderPath)) { Directory.CreateDirectory(unifolderPath); } File.Copy(Path.Combine(directoryName, name) + ".kml", Path.Combine(disfolderPath, name) + ".kml", true); File.Copy(Path.Combine(directoryName, name) + ".png", Path.Combine(disfolderPath, name) + ".png", true); File.Copy(Path.Combine(directoryName, name) + ".tif", Path.Combine(rawfolderPath, name) + ".tif", true); SaveDailyLatestKmlAndPng(unifolderPath, kmlFileNames[i]); } // Delete temp uncompress directory Directory.Delete(unCompressFolder, true); }