Ejemplo n.º 1
0
        private bool GetFiles()
        {
            bool status = true;

            Sftp sftp = new Sftp(m_sftpSite, m_sftpSiteUserName);

            try
            {
                // add our private key to connect
                // put these in the config file
                sftp.AddIdentityFile(m_identityFile);

                // connect
                sftp.Connect();

                // get a directory list
                ArrayList rFiles = sftp.GetFileList(m_sftpSiteRemoteFolder);
                int       indx   = 0;
                foreach (string file in rFiles)
                {
                    indx++;
                    if (file.Equals(".") || file.Equals(".."))
                    {
                        continue;
                    }

                    if (this.CheckDb(file))
                    {
                        continue;
                    }

                    try
                    {
                        // get the file and put in the watch folder to be processed
                        sftp.Get(m_sftpSiteRemoteFolder + file, m_moveToProcessFolder + file);

                        // update the database to indicate file has been downloaded
                        this.UpdateDb(file);

                        // delete the file on the remote server after pulling it over
                        // sftp.Delete(f);
                    }
                    catch (SystemException se)
                    {
                        LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:TryingToGetFile:" + indx + ":" + file + "::" + se.Message);
                    }
                }

                sftp.Close();
                status = true;
            }
            catch (Tamir.SharpSsh.jsch.SftpException se)
            {
                LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message);
            }
            catch (Tamir.SharpSsh.jsch.JSchException jse)
            {
                LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + jse.Message);
            }
            catch (Tamir.SharpSsh.SshTransferException ste)
            {
                LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + ste.Message);
            }
            catch (SystemException se)
            {
                LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message);
            }

            return(status);
        } // getFile()