Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="clientCode"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        public static int MoveFtpFilesToDirectory(string source, string destination, string clientCode, IEnumerable <string> files)
        {
            int count = 0;

            try
            {
                clsFTP ftp = OpenFtp(source);
                try
                {
                    foreach (string file in files)
                    {
                        if (!string.IsNullOrEmpty(file))
                        {
                            string destFileName = String.Format("{0}\\{1}_{2}", destination, clientCode, file);
                            ftp.DownloadFile(file, destFileName);
                            if (!ftp.DeleteFile(file))
                            {
                                ErrorLog.LogError(String.Format("Unable to FTP delete {0}", file), new CallingMethod());
                            }
                            ++count;
                        }
                    }
                }
                finally
                {
                    ftp.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogError(ex.Message, new CallingMethod());
            }
            return(count);
        }
Example #2
0
        private static void CopiarArquivoServidorFTP(string NomeArquivoFTP, string NomeArquivoLocal)
        {
            try
            {
                clsFTP ftp = new clsFTP();
                ftp.RemotePort     = Convert.ToInt32(LerGravarXML.ObterValor("FTPPorta", "21"));
                ftp.RemoteHost     = LerGravarXML.ObterValor("FTPEnderecoServidor", "cabtec.sinaf.com.br");
                ftp.UsarLan        = (LerGravarXML.ObterValor("FTPPassivo", "N") == "S" ? true : false);
                ftp.RemoteUser     = LerGravarXML.ObterValor("FTPUser", "cabtec");
                ftp.RemotePassword = LerGravarXML.ObterValor("FTPPassword", "cab003");

                ftp.Login();

                string ftpCaminho = NomeArquivoFTP.Substring(NomeArquivoFTP.LastIndexOf("TEMP"));
                ftpCaminho = ftpCaminho.Substring(0, ftpCaminho.LastIndexOf("\\") + 1);
                ftpCaminho = ftpCaminho.Replace('\\', '/');
                ftp.ChangeDirectory(@"/" + ftpCaminho);

                NomeArquivoFTP = NomeArquivoFTP.Substring(NomeArquivoFTP.LastIndexOf("\\") + 1);
                ftp.DownloadFile(NomeArquivoFTP, NomeArquivoLocal);
                ftp.DeleteFile(NomeArquivoFTP);

                ftp.CloseConnection();
                ftp = null;
            }
            catch (Exception ex)
            {
                LogErro.GravaLog("Acessando servidor FTP!", ex.Message);
                throw ex;
            }
        }