3 using System.Collections.Generic;
17 public string _MsgError =
string.Empty;
25 public string _FileLocal =
string.Empty;
26 #endregion Propiedades 28 #region Métodos públicos 39 _FileLocal =
string.Empty;
45 if (!Directory.Exists(lcDirTemp))
46 FUNCTIONS._CrearCarpetaTemp(lcDirTemp);
47 string lcFileName = Path.Combine(lcDirTemp, datosFtp.
_Archivo);
49 string lcFileFtp = null;
54 lcFileFtp = lcRemoteUri +
"//" + datosFtp.
_Carpeta + (
string.IsNullOrWhiteSpace(datosFtp.
_Carpeta) ?
"" :
"//") + datosFtp.
_Archivo;
56 FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(lcFileFtp);
57 if (!
string.IsNullOrWhiteSpace(datosFtp.
_Proxy))
59 WebProxy proxyObject =
new WebProxy(datosFtp.
_Proxy,
true);
60 ftpRequest.Proxy = proxyObject;
63 ftpRequest.EnableSsl = datosFtp.
_Secure;
66 ServicePointManager.ServerCertificateValidationCallback =
67 (sender, certificate, chain, errors) =>
73 ftpRequest.Timeout = 10000;
74 ftpRequest.Credentials =
new NetworkCredential(datosFtp.
_User, datosFtp.
_Password);
75 ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
78 using (Stream ftpStream = ftpRequest.GetResponse().GetResponseStream())
80 using (Stream fileStream = File.Create(lcFileName))
82 ftpStream.CopyTo(fileStream);
87 catch (Exception loEx)
90 _MsgError = loEx.Message;
95 ServicePointManager.ServerCertificateValidationCallback = null;
99 _FileLocal = lcFileName;
102 return llOk && File.Exists(lcFileName);
105 #endregion Métodos públicos 107 #region Clase DatosFP 118 public string _Server
120 get {
return _cServer; }
121 set { _cServer = value; }
123 private string _cServer =
"";
130 get {
return _cUser; }
131 set { _cUser = value; }
133 private string _cUser =
"";
139 public string _Password
141 get {
return _cPassword; }
142 set { _cPassword = value; }
144 private string _cPassword =
"";
150 public string _Carpeta
152 get {
return _cCarpeta; }
153 set { _cCarpeta = value; }
155 private string _cCarpeta =
"";
161 public string _Archivo
163 get {
return _cArchivo; }
164 set { _cArchivo = value; }
166 private string _cArchivo =
"";
171 public string _CarpetaLocal
173 get {
return _cCarpetaLocal; }
174 set { _cCarpetaLocal = value; }
176 private string _cCarpetaLocal =
"";
183 get {
return _nPuerto; }
184 set { _nPuerto = value; }
186 private int _nPuerto = 21;
193 get {
return _cProxy; }
194 set { _cProxy = value; }
196 private string _cProxy =
"";
203 get {
return _lSecure; }
204 set { _lSecure = value; }
206 private bool _lSecure =
false;
211 public bool _ValidateServerCert
213 get {
return _lValidateServerCert; }
214 set { _lValidateServerCert = value; }
216 private bool _lValidateServerCert =
false;
221 public bool _Ftp_activo
223 get {
return _lFtp_activo; }
224 set { _lFtp_activo = value; }
226 private bool _lFtp_activo =
false;
236 #endregion Constructor 244 string lcRemoteUri = $
"{_Server}:{_Puerto}";
246 if (!lcRemoteUri.ToLower().StartsWith(
"ftp:") && !lcRemoteUri.ToLower().StartsWith(
"http"))
248 lcRemoteUri =
"ftp://" + lcRemoteUri;
255 #endregion Clase DatosFP Clase con los datos para la descarga
bool _Ftp_activo
Ftp activo
string _Carpeta
carpeta del FTP
bool _ValidateServerCert
validar certificado servidor
bool _DescargarArchivoFTP(DatosFTP datosFtp)
Método para descargar un archivo
Clase para la descarga de ficheros FTP
string _CarpetaLocal
carpeta local
string _Archivo
archivo del FTP
string ToRemoteUri()
Devuelve la Uri del servidor