/// <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); }
private static clsFTP OpenFtp(string source) { try { string[] parms = source.Split(';'); Assert.Test(parms.Length >= 5 && String.Compare(parms[0], "FTP", true) == 0, "CheckFtpSourceForWorkFiles parsing error"); clsFTP ftp = new clsFTP(); ftp.RemoteUser = parms[1]; ftp.RemotePassword = parms[2]; ftp.RemoteHost = parms[3]; Assert.Test(ftp.Login(), "CheckFtpSourceForWorkFiles ftp login failed"); Assert.Test(ftp.ChangeDirectory(parms[4]), "CheckFtpSourceForWorkFiles change directory failed"); ftp.SetBinaryMode(true); return(ftp); } catch (Exception ex) { ErrorLog.LogError(ex.Message, new CallingMethod()); } return(null); }
private static void MandarArquivoServidorFTP(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 numero = new Symbol.ResourceCoordination.TerminalInfo().ESN; string diretorio = LerGravarXML.ObterValor("FTPDiretorio", @"/TEMP/"); ftp.ChangeDirectory(diretorio + numero); ftp.UploadFile(NomeArquivoLocal); ftp.CloseConnection(); ftp = null; } catch (Exception ex) { throw ex; } }
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; } }
private static string[] GetFtpFileList(string source, string pattern) { string[] files = null; try { clsFTP ftp = OpenFtp(source); try { files = ftp.GetFileList(pattern); } finally { ftp.CloseConnection(); } } catch (Exception ex) { ErrorLog.DebugLog(ex.Message, "FileUtility"); } return(files ?? new string[] { }); }