public int ReadDirFraSFtp() { int AntalFiler = 0; m_memPbsnetdir = new MemPbsnetdir(); //opret ny memPbsnetdir // Iterate over the files. foreach (SftpFile fileObj in m_sftp.ListDirectory(m_rec_sftp.outbound)) { if (fileObj.Name != "." && fileObj.Name != "..") { recPbsnetdir rec = new recPbsnetdir { Type = 8, Path = m_rec_sftp.outbound, Filename = fileObj.Name, Size = (int)fileObj.Length, Atime = fileObj.LastAccessTime, Mtime = fileObj.LastWriteTime, Gid = fileObj.GroupId, Uid = fileObj.UserId, Perm = "" }; m_memPbsnetdir.Add(rec); AntalFiler++; } } return(AntalFiler); }
public int ReadFraSFtp(dbData3060 p_dbData3060) { m_memPbsnetdir = new MemPbsnetdir(); //opret ny memPbsnetdir // Iterate over the files. foreach (SftpFile fileObj in m_sftp.ListDirectory(m_rec_sftp.outbound)) { if (fileObj.Name != "." && fileObj.Name != "..") { recPbsnetdir rec = new recPbsnetdir { Type = 8, Path = m_rec_sftp.outbound, Filename = fileObj.Name, Size = (int)fileObj.Length, Atime = fileObj.LastAccessTime, Mtime = fileObj.LastWriteTime, Gid = fileObj.GroupId, Uid = fileObj.UserId, Perm = "" }; m_memPbsnetdir.Add(rec); } } var leftqry_pbsnetdir = from h in m_memPbsnetdir //join d1 in p_dbData3060.Tblpbsfiles on new { h.Path, h.Filename } equals new { d1.Path, d1.Filename } into details //from d1 in details.DefaultIfEmpty(new Tblpbsfiles { Id = -1, Type = (int?)null, Path = null, Filename = null, Size = (int?)null, Atime = (DateTime?)null, Mtime = (DateTime?)null, Perm = null, Uid = (int?)null, Gid = (int?)null }) //where d1.Path == null && d1.Filename == null select h; int AntalFiler = leftqry_pbsnetdir.Count(); if (leftqry_pbsnetdir.Count() > 0) { foreach (var rec_pbsnetdir in leftqry_pbsnetdir) { tblpbsfilename m_rec_pbsfiles = new tblpbsfilename { type = rec_pbsnetdir.Type, path = rec_pbsnetdir.Path, filename = rec_pbsnetdir.Filename, size = rec_pbsnetdir.Size, atime = rec_pbsnetdir.Atime, mtime = rec_pbsnetdir.Mtime, perm = rec_pbsnetdir.Perm, uid = rec_pbsnetdir.Uid, gid = rec_pbsnetdir.Gid }; p_dbData3060.tblpbsfilename.Add(m_rec_pbsfiles); //*********************************************************************** // Open a file on the server: string fullpath = rec_pbsnetdir.Path + "/" + rec_pbsnetdir.Filename; int numBytes = (int)rec_pbsnetdir.Size; byte[] b_data = new byte[numBytes]; MemoryStream stream = new MemoryStream(b_data, true); Program.Log(string.Format("Start Download of {0}", fullpath)); m_sftp.DownloadFile(fullpath, stream); Program.Log(string.Format("{0} Download Completed", fullpath)); sendAttachedFile(p_dbData3060, rec_pbsnetdir.Filename, b_data, false); char[] c_data = System.Text.Encoding.GetEncoding("windows-1252").GetString(b_data).ToCharArray(); string filecontens = new string(c_data); string filecontens2 = filecontens.TrimEnd('\n'); string filecontens3 = filecontens2.TrimEnd('\r'); string filecontens4 = filecontens3.TrimEnd('\n'); string[] lines = filecontens4.Split('\n'); string ln = null; int seqnr = 0; string ln0_6; for (int idx = 0; idx < lines.Count(); idx++) { ln = lines[idx].TrimEnd('\r'); try { ln0_6 = ln.Substring(0, 6); } catch { ln0_6 = ""; } if (((seqnr == 0) && !(ln0_6 == "PBCNET")) || (seqnr > 0)) { seqnr++; } if (ln.Length > 0) { m_rec_pbsfile = new tblpbsfile { seqnr = seqnr, data = ln }; m_rec_pbsfiles.tblpbsfile.Add(m_rec_pbsfile); } } m_rec_pbsfiles.transmittime = DateTime.Now; //var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString); Program.Log(string.Format("Start Write {0} to SQL Database {1} on {2}", rec_pbsnetdir.Filename, "cb.InitialCatalog", "cb.DataSource")); p_dbData3060.SaveChanges(); Program.Log(string.Format("{0} Write to SQL Database Completed", rec_pbsnetdir.Filename)); } } p_dbData3060.SaveChanges(); return(AntalFiler); }