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?
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?
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))
{
...
}
}
}
}
...