varios usar subir net archivos c# ftp download networkcredentials

usar - subir varios archivos ftp c#



C#archivo Ășnico FTP de descarga (2)

Estoy tratando de descargar un archivo usando FTP dentro de una aplicación de consola C #, pero aunque ahora las rutas son correctas siempre recibo un error que dice "archivo 550 no encontrado".

¿Hay alguna forma de devolver la ruta actual (una vez conectado al servidor)?

// lade datei von FTP server string ftpfullpath = "ftp://" + Properties.Settings.Default.FTP_Server + Properties.Settings.Default.FTP_Pfad + "/" + Properties.Settings.Default.FTP_Dateiname; Console.WriteLine("Starte Download von: " + ftpfullpath); using (WebClient request = new WebClient()) { request.Credentials = new NetworkCredential(Properties.Settings.Default.FTP_User, Properties.Settings.Default.FTP_Passwort); byte[] fileData = request.DownloadData(ftpfullpath); using (FileStream file = File.Create(@path + "/tmp/" + Properties.Settings.Default.FTP_Dateiname)) { file.Write(fileData, 0, fileData.Length); file.Close(); } Console.WriteLine("Download abgeschlossen!"); }

EDIT Mi error. Se corrigió el archivo, aún obteniendo el mismo error. Pero si me conecto con FileZilla esa es la ruta exacta del archivo.


Creo que tu nombre de archivo es incorrecto. Su primera línea escribe un nombre diferente al que configuró en ftpfullpath. Usted nos FTP_Dateiname en la primera línea pero FTP_Pfad cuando establece ftpfullpath.

Para ver lo que está sucediendo, mueva su primera línea después de ''string ftpfullpath ...'')

y cambiarlo a Console.WriteLine ("Starte Download von:" + ftpfullpath);


Finalmente encontré una solución usando System.Net.FtpClient ( https://netftp.codeplex.com/releases/view/95632 ) y usando el siguiente código.

// aktueller pfad string apppath = Directory.GetCurrentDirectory(); Console.WriteLine("Bereite Download von FTP Server vor!"); using (var ftpClient = new FtpClient()) { ftpClient.Host = Properties.Settings.Default.FTP_Server; ftpClient.Credentials = new NetworkCredential(Properties.Settings.Default.FTP_User, Properties.Settings.Default.FTP_Passwort); var destinationDirectory = apppath + "//Input"; ftpClient.Connect(); var destinationPath = string.Format(@"{0}/{1}", destinationDirectory, Properties.Settings.Default.FTP_Dateiname); Console.WriteLine("Starte Download von " + Properties.Settings.Default.FTP_Dateiname + " nach " + destinationPath); using (var ftpStream = ftpClient.OpenRead(Properties.Settings.Default.FTP_Pfad + "/" + Properties.Settings.Default.FTP_Dateiname)) using (var fileStream = File.Create(destinationPath , (int)ftpStream.Length)) { var buffer = new byte[8 * 1024]; int count; while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0) { fileStream.Write(buffer, 0, count); } } }