Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void ReadDirectoryFraSFtp()
        {
            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.Tblpbsnetdir on new { h.Path, h.Filename } equals new { d1.Path, d1.Filename } into details
            from d1 in details.DefaultIfEmpty(new Tblpbsnetdir {
                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();
            string MailBody   = "";

            if (leftqry_pbsnetdir.Count() > 0)
            {
                foreach (var rec_pbsnetdir in leftqry_pbsnetdir)
                {
                    MailBody += "\n" + rec_pbsnetdir.Filename + " - " + rec_pbsnetdir.Mtime.ToString() + " - " + rec_pbsnetdir.Size.ToString();

                    Tblpbsnetdir m_rec_pbsnetdir = new Tblpbsnetdir
                    {
                        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.Tblpbsnetdir.InsertOnSubmit(m_rec_pbsnetdir);
                }
                sendAttachedFile(MailBody);
            }
            Program.dbData3060.SubmitChanges();
            return;
        }