Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creamos el objeto de conexión con las propiedades de acceso.
- using (var ftpClient = new FtpClient(new FtpClientConfiguration
- {
- Host = "ftp.blabla.com",
- Username = "usuario",
- Password = "password",
- IgnoreCertificateErrors = true
- }))
- {
- // Hacemos el login
- try
- {
- await ftpClient.LoginAsync();
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- // Si todo OK.
- if (ftpClient.IsAuthenticated)
- {
- // Nos posicionamos en el directorio del ftp donde están los archivos a descargar.
- await ftpClient.ChangeWorkingDirectoryAsync("directorio");
- // Obtenemos una lista de los ficheros
- var archivos = ftpClient.ListFilesAsync().Result.Where(a => Path.GetExtension(a.Name) == ".gz").OrderBy(a => a.DateModified);
- // Los recorremos...
- foreach (var archivo in archivos)
- {
- //Obtenemos el contenido del archivo.
- using (var ftpReadStream = await ftpClient.OpenFileReadStreamAsync(archivo.Name))
- {
- ...
- }
- }
- }
- }
- ...
Add Comment
Please, Sign In to add comment