public H08(string Product) { try { Ftp.Client theFTP = new Ftp.Client("ftp://10.8.3.193", "admin", "123comparex"); theFTP.ChangeWorkingDirectory("DVUGMS"); theFTP.ChangeWorkingDirectory("SINOPTIC"); theFTP.ChangeWorkingDirectory("H08"); theFTP.ChangeWorkingDirectory(Product); string pathLast = theFTP.ListDirectory().Where(x => x.Substring(0, 3).Contains("cld")).OrderByDescending(x => x.ToLower()).First(); string fileTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tmp"; theFTP.DownloadFile(pathLast, fileTemp); using (Image image = Image.FromFile(fileTemp)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); this.base64String = base64String; } } System.IO.File.Delete(fileTemp); } catch (Exception ex) { this.base64String = ex.Message; } }
public ActionResult Load(string Catalog) { List <String> theList = new List <String>(); ViewBag.Catalog = Catalog; try { Ftp.Client theFTP = new Ftp.Client("ftp://10.8.3.193", "admin", "123comparex"); theFTP.ChangeWorkingDirectory("DVUGMS"); theFTP.ChangeWorkingDirectory("SINOPTIC"); theFTP.ChangeWorkingDirectory("H08"); theFTP.ChangeWorkingDirectory(Catalog); int i = 0; foreach (var item in theFTP.ListDirectory().Where(x => x.Substring(0, 3).Contains("cld")).OrderByDescending(x => x.ToLower())) { i++; if (i == 10) { break; } string fileTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tmp"; theFTP.DownloadFile(item, fileTemp); using (Image image = Image.FromFile(fileTemp)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); theList.Add(base64String); } } System.IO.File.Delete(fileTemp); } theList.Reverse(); } catch (Exception er) { ViewBag.Error = er.Message; } return(View(theList)); }
void IGroza.Access() { try { Ftp.Client theFTP = new Ftp.Client("ftp://" + Groza_FTP_host, Groza_FTP_user, Groza_FTP_pass); foreach (var item in theFTP.ListDirectory()) { theLogger.Log(item); if (MeteologyEntity.Models.Groza.Groza.GetByZOC(item).Count > 0) { theLogger.Log("Count > 0"); continue; } theLogger.Log("Count == 0"); string fileTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".zoc"; theFTP.DownloadFile(item, fileTemp); foreach (var line in File.ReadAllLines(fileTemp)) { theLogger.Log(line); MeteologyEntity.Models.Groza.Groza theGroza = new MeteologyEntity.Models.Groza.Groza(item, line); theGroza.Save(); } File.Delete(fileTemp); } } catch (Exception ex) { theLogger.Error(ex.Message); theLogger.Error(ex.StackTrace); theLogger.Error(this.Groza_FTP_host); theLogger.Error(this.Groza_FTP_user); theLogger.Error(this.Groza_FTP_pass); if (ex.InnerException != null) { theLogger.Error(ex.InnerException.Message); } } }