Exemple #1
0
        public int ReadDirFraSFtp()
        {
            int AntalFiler = 0;

            Program.memPbsnetdir = null; //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     = ""
                    };
                    Program.memPbsnetdir.Add(rec);
                    AntalFiler++;
                }
            }

            return(AntalFiler);
        }
Exemple #2
0
        public void ReadDirFraSFtp()
        {
            string homedir = m_sftp.RealPath(".", "");
            //  Open a directory on the server...
            string handle = m_sftp.OpenDir(m_rec_sftp.Outbound);

            if (handle == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            //  Download the directory listing:
            Chilkat.SFtpDir dirListing = null;
            dirListing = m_sftp.ReadDir(handle);
            if (dirListing == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            Program.memPbsnetdir = null; //opret ny memPbsnetdir

            //  Iterate over the files.
            int i;
            int n = dirListing.NumFilesAndDirs;

            if (n > 0)
            {
                for (i = 0; i <= n - 1; i++)
                {
                    Chilkat.SFtpFile fileObj = null;
                    fileObj = dirListing.GetFileObject(i);
                    if (!fileObj.IsDirectory)
                    {
                        recPbsnetdir rec = new recPbsnetdir
                        {
                            Type     = 8,
                            Path     = dirListing.OriginalPath,
                            Filename = fileObj.Filename,
                            Size     = (int)fileObj.Size32,
                            Atime    = fileObj.LastAccessTime,
                            Mtime    = fileObj.LastModifiedTime,
                            Gid      = fileObj.Gid,
                            Uid      = fileObj.Uid,
                            Perm     = fileObj.Permissions.ToString()
                        };
                        Program.memPbsnetdir.Add(rec);
                    }
                }
            }

            //  Close the directory
            bool success = m_sftp.CloseHandle(handle);

            if (!success)
            {
                throw new Exception(m_sftp.LastErrorText);
            }
        }
Exemple #3
0
        public int ReadFraPbsFile()
        {
            string        FraPBSFolderPath;
            DirectoryInfo fld;
            FileStream    ts;
            string        ln;

            Program.memPbsnetdir = null; //opret ny memPbsnetdir
            var rec_regnskab = Program.qryAktivRegnskab();

            FraPBSFolderPath = rec_regnskab.FraPBS;

            fld = new DirectoryInfo(FraPBSFolderPath);
            foreach (FileInfo f in fld.GetFiles())
            {
                recPbsnetdir rec = new recPbsnetdir
                {
                    Type     = 8,
                    Path     = f.Directory.Name,
                    Filename = f.Name,
                    Size     = (int)f.Length,
                    Atime    = f.LastAccessTime,
                    Mtime    = f.LastWriteTime
                };
                Program.memPbsnetdir.Add(rec);
            }
            var leftqry_pbsnetdir =
                from h in Program.memPbsnetdir
                join d1 in Program.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)
                {
                    Tblpbsfiles m_rec_pbsfiles = new Tblpbsfiles
                    {
                        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
                    };
                    Program.dbData3060.Tblpbsfiles.InsertOnSubmit(m_rec_pbsfiles);

                    string varFromFile = FraPBSFolderPath + rec_pbsnetdir.Filename;
                    int    seqnr       = 0;
                    ts = new FileStream(varFromFile, FileMode.Open, FileAccess.Read, FileShare.None);
                    ln = null;
                    using (StreamReader sr = new StreamReader(ts, Encoding.Default))
                    {
                        while ((ln = sr.ReadLine()) != null)
                        {
                            if (((seqnr == 0) && !(ln.Substring(0, 6) == "PBCNET")) || (seqnr > 0))
                            {
                                seqnr++;
                            }
                            m_rec_pbsfile = new Tblpbsfile
                            {
                                Seqnr = seqnr,
                                Data  = ln
                            };
                            m_rec_pbsfiles.Tblpbsfile.Add(m_rec_pbsfile);
                        }
                    }
                    m_rec_pbsfiles.Transmittime = DateTime.Now;
                    Program.dbData3060.SubmitChanges();
                }
            }
            Program.dbData3060.SubmitChanges();
            return(AntalFiler);
        }
Exemple #4
0
        public int ReadFraSFtp()
        {
            string homedir = m_sftp.RealPath(".", "");
            //  Open a directory on the server...
            string handle = m_sftp.OpenDir(m_rec_sftp.Outbound);

            if (handle == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            //  Download the directory listing:
            Chilkat.SFtpDir dirListing = null;
            dirListing = m_sftp.ReadDir(handle);
            if (dirListing == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            Program.memPbsnetdir = null; //opret ny memPbsnetdir

            //  Iterate over the files.
            int i;
            int n = dirListing.NumFilesAndDirs;

            if (n > 0)
            {
                for (i = 0; i <= n - 1; i++)
                {
                    Chilkat.SFtpFile fileObj = null;
                    fileObj = dirListing.GetFileObject(i);
                    if (!fileObj.IsDirectory)
                    {
                        recPbsnetdir rec = new recPbsnetdir
                        {
                            Type     = 8,
                            Path     = dirListing.OriginalPath,
                            Filename = fileObj.Filename,
                            Size     = (int)fileObj.Size32,
                            Atime    = fileObj.LastAccessTime,
                            Mtime    = fileObj.LastModifiedTime,
                            Gid      = fileObj.Gid,
                            Uid      = fileObj.Uid,
                            Perm     = fileObj.Permissions.ToString()
                        };
                        Program.memPbsnetdir.Add(rec);
                    }
                }
            }

            //  Close the directory
            bool success = m_sftp.CloseHandle(handle);

            if (!success)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            var leftqry_pbsnetdir =
                from h in Program.memPbsnetdir
                //join d1 in Program.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)
                {
                    Tblpbsfiles m_rec_pbsfiles = new Tblpbsfiles
                    {
                        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
                    };
                    Program.dbData3060.Tblpbsfiles.InsertOnSubmit(m_rec_pbsfiles);

                    //***********************************************************************
                    //  Open a file on the server:
                    string fullpath   = rec_pbsnetdir.Path + "/" + rec_pbsnetdir.Filename;
                    string filehandle = m_sftp.OpenFile(fullpath, "readOnly", "openExisting");
                    if (filehandle == null)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }

                    int numBytes = (int)rec_pbsnetdir.Size;
                    if (numBytes < 0)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }

                    //---------------------------------------------------------------------
                    byte[] b_data        = null;
                    bool   bEof          = false;
                    int    chunkSizeGet  = 10240;
                    int    chunkSizeRead = 0;
                    m_sftp.ClearAccumulateBuffer();
                    while (bEof == false)
                    {
                        chunkSizeRead = m_sftp.AccumulateBytes(handle, chunkSizeGet);
                        if (chunkSizeRead == -1)
                        {
                            throw new Exception(m_sftp.LastErrorText);
                        }
                        bEof = m_sftp.Eof(handle);
                    }
                    b_data = m_sftp.AccumulateBuffer;
                    //---------------------------------------------------------------------
                    if (b_data == null)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }
                    sendAttachedFile(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;
                    Program.dbData3060.SubmitChanges();

                    //  Close the file.
                    success = m_sftp.CloseHandle(filehandle);
                    if (success != true)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }
                    //***********************************************************************************
                }
            }
            Program.dbData3060.SubmitChanges();
            return(AntalFiler);
        }
Exemple #5
0
        public int ReadFraSFtp()
        {
            string homedir = m_sftp.RealPath(".", "");
            //  Open a directory on the server...
            string handle = m_sftp.OpenDir(m_Outbound);

            if (handle == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            //  Download the directory listing:
            Chilkat.SFtpDir dirListing = null;
            dirListing = m_sftp.ReadDir(handle);
            if (dirListing == null)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            Program.memPbsnetdir = null; //opret ny memPbsnetdir

            //  Iterate over the files.
            int i;
            int n = dirListing.NumFilesAndDirs;

            if (n > 0)
            {
                for (i = 0; i <= n - 1; i++)
                {
                    Chilkat.SFtpFile fileObj = null;
                    fileObj = dirListing.GetFileObject(i);
                    if (!fileObj.IsDirectory)
                    {
                        DateTime     testLastAccessTime = fileObj.LastAccessTime;
                        recPbsnetdir rec = new recPbsnetdir
                        {
                            Type     = 8,
                            Path     = dirListing.OriginalPath,
                            Filename = fileObj.Filename,
                            Size     = (int)fileObj.Size32,
                            Atime    = Unspecified2Utc(fileObj.LastAccessTime),
                            Mtime    = Unspecified2Utc(fileObj.LastModifiedTime),
                            Gid      = fileObj.Gid,
                            Uid      = fileObj.Uid,
                            Perm     = fileObj.Permissions.ToString()
                        };
                        Program.memPbsnetdir.Add(rec);
                    }
                }
            }

            //  Close the directory
            bool success = m_sftp.CloseHandle(handle);

            if (!success)
            {
                throw new Exception(m_sftp.LastErrorText);
            }

            var leftqry_pbsnetdir = from h in Program.memPbsnetdir select h;

            int AntalFiler = leftqry_pbsnetdir.Count();

            if (leftqry_pbsnetdir.Count() > 0)
            {
                foreach (var rec_pbsnetdir in leftqry_pbsnetdir)
                {
                    //  Open a file on the server:
                    string fullpath   = rec_pbsnetdir.Path + "/" + rec_pbsnetdir.Filename;
                    string filehandle = m_sftp.OpenFile(fullpath, "readOnly", "openExisting");
                    if (filehandle == null)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }

                    int numBytes = (int)rec_pbsnetdir.Size;
                    if (numBytes < 0)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }

                    byte[] b_data = null;
                    b_data = m_sftp.ReadFileBytes(handle, numBytes);
                    if (b_data == null)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }
                    sendAttachedFile(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');

                    XElement xmlPbsfilesAdd = new XElement("Pbsfiles");
                    xmlPbsfilesAdd.Add(new XElement("Type", rec_pbsnetdir.Type));
                    xmlPbsfilesAdd.Add(new XElement("Path", rec_pbsnetdir.Path));
                    xmlPbsfilesAdd.Add(new XElement("Filename", rec_pbsnetdir.Filename));
                    xmlPbsfilesAdd.Add(new XElement("Size", rec_pbsnetdir.Size));
                    xmlPbsfilesAdd.Add(new XElement("Atime", rec_pbsnetdir.Atime));
                    xmlPbsfilesAdd.Add(new XElement("Mtime", rec_pbsnetdir.Mtime));
                    xmlPbsfilesAdd.Add(new XElement("Transmittime", DateTime.Now));
                    xmlPbsfilesAdd.Add(new XElement("Data", filecontens4));
                    string strxmlPbsfilesAdd = @"<?xml version=""1.0"" encoding=""utf-8"" ?> " + xmlPbsfilesAdd.ToString();

                    Guid id1 = clsSQLite.insertStoreXML(Program.AppEngName, false, Program.sftpName, strxmlPbsfilesAdd, "");

                    clsRest   objRest    = new clsRest();
                    string    strxmldata = objRest.HttpPost2(clsRest.urlBaseType.data, "frapbs", strxmlPbsfilesAdd);
                    XDocument xmldata    = XDocument.Parse(strxmldata);
                    string    Status     = xmldata.Descendants("Status").First().Value;
                    if (Status == "True")
                    {
                        clsSQLite.updateStoreXML(id1, true);
                    }

                    //  Close the file.
                    success = m_sftp.CloseHandle(filehandle);
                    if (success != true)
                    {
                        throw new Exception(m_sftp.LastErrorText);
                    }
                }
            }
            return(AntalFiler);
        }
Exemple #6
0
        public int ReadFraSFtp()
        {
            Program.memPbsnetdir = null; //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     = ""
                    };
                    Program.memPbsnetdir.Add(rec);
                }
            }

            var leftqry_pbsnetdir =
                from h in Program.memPbsnetdir
                //join d1 in Program.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
                    };
                    Program.dbData3060.tblpbsfilenames.InsertOnSubmit(m_rec_pbsfiles);

                    //***********************************************************************
                    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);

                    m_sftp.DownloadFile(fullpath, stream);
                    sendAttachedFile(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.tblpbsfiles.Add(m_rec_pbsfile);
                        }
                    }

                    m_rec_pbsfiles.transmittime = DateTime.Now;
                    Program.dbData3060.SubmitChanges();
                    //***********************************************************************************
                }
            }
            Program.dbData3060.SubmitChanges();
            return(AntalFiler);
        }