FTP ASP.NET Core MVC

0

It seems to me that FtpWebRequest is not implemented in Core MVC ...

Any bookstore or something like that to download a file via FTP with the mvc core?

    
asked by Joseba Rodríguez 10.04.2017 в 13:22
source

1 answer

0

Here I leave some code of how to connect to ftp, etc ...

// Creamos el objeto ftp 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.
// Puedes filtar y ordenar el resultado si es necesario.
                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))
                        {
                        ...    

                        }
                 }
             }
         }
 ...
    
answered by 10.03.2018 / 13:13
source