public DTORespuestaFTP obtenerRutas(string Usuario, string Password, int TipoDocumento, int NumeroMuestra) { DTORespuestaFTP respuesta = new DTORespuestaFTP(); try { this._servicios = new MServicios(); //Validar el usuario. DTOUsuario usuario = new DTOUsuario() { Password = Password, Nombre = Usuario }; if (!this._servicios.IsUsuarioValido(usuario)) { throw new Exception("ERROR: Credenciales de usuario son incorrectas."); } DTOInforme informe = new DTOInforme(); informe.TipoDocumento = TipoDocumento; informe.NumeroMuestra = NumeroMuestra; if (informe == null) { throw new Exception("ERROR: El parámetro de entrada no puede ser nulo."); } respuesta = this._servicios.obtenerArchivo(informe); return(respuesta); } catch (Exception ex) { respuesta.Resultado = false; respuesta.Mensaje = "WebService.obtenerRutas: " + ex.Message; return(respuesta); } }
public DTORespuestaFTP obtenerArchivo(DTOInforme informe) { DTORespuestaFTP respuesta = new DTORespuestaFTP(); try { SFTP ftp = new SFTP(); string carpeta = ""; switch (informe.TipoDocumento) { case 1: carpeta = WebConfigurationManager.AppSettings["ftp_informes"]; break; case 2: carpeta = WebConfigurationManager.AppSettings["ftp_ecfa"]; break; default: throw new Exception("ERROR: El tipo de documento no es correcto: 1=Informe/2=ECFA"); } List <string> contenido = ftp.obtenerContenido(carpeta); string archivoFormat; foreach (string archivo in contenido) { archivoFormat = archivo.Replace(carpeta, ""); archivoFormat = archivoFormat.Replace("/", ""); archivoFormat = archivoFormat.Replace(".", ""); if (archivoFormat.Split('_')[0].ToString().Equals(informe.NumeroMuestra.ToString())) { respuesta.Rutas.Add(archivo); } } if (respuesta.Rutas.Count == 0) { throw new Exception("ERROR: No se encontraron archivos en '" + carpeta + "' para el informe '" + informe.NumeroMuestra.ToString() + "'"); } respuesta.Mensaje = "Servicio ejecutado correctamente."; respuesta.Resultado = true; } catch (Exception ex) { throw new Exception("MServicios.obtenerArchivo: " + ex.Message); } return(respuesta); }