Guest User

Untitled

a guest
Mar 10th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // Creamos el objeto de conexión con las propiedades de acceso.
  2. using (var ftpClient = new FtpClient(new FtpClientConfiguration
  3. {
  4. Host = "ftp.blabla.com",
  5. Username = "usuario",
  6. Password = "password",
  7. IgnoreCertificateErrors = true
  8. }))
  9. {
  10. // Hacemos el login
  11. try
  12. {
  13. await ftpClient.LoginAsync();
  14. }
  15. catch (Exception ex)
  16. {
  17. return ex.Message;
  18. }
  19.  
  20. // Si todo OK.
  21. if (ftpClient.IsAuthenticated)
  22. {
  23. // Nos posicionamos en el directorio del ftp donde están los archivos a descargar.
  24. await ftpClient.ChangeWorkingDirectoryAsync("directorio");
  25.  
  26. // Obtenemos una lista de los ficheros
  27. var archivos = ftpClient.ListFilesAsync().Result.Where(a => Path.GetExtension(a.Name) == ".gz").OrderBy(a => a.DateModified);
  28.  
  29. // Los recorremos...
  30. foreach (var archivo in archivos)
  31. {
  32. //Obtenemos el contenido del archivo.
  33. using (var ftpReadStream = await ftpClient.OpenFileReadStreamAsync(archivo.Name))
  34. {
  35. ...
  36.  
  37. }
  38. }
  39. }
  40. }
  41. ...
Add Comment
Please, Sign In to add comment