Foros del Web » Programación para mayores de 30 ;) » .NET »

Descargar varios txt de un servidor ftp

Estas en el tema de Descargar varios txt de un servidor ftp en el foro de .NET en Foros del Web. Saludos, Les comento mi problema. Resulta que necesito descargar unos ficheros desde un servidor ftp y eh buscado mucho y lo que logre encontrar solo ...
  #1 (permalink)  
Antiguo 11/01/2011, 13:47
Avatar de rockex  
Fecha de Ingreso: diciembre-2008
Mensajes: 45
Antigüedad: 15 años, 4 meses
Puntos: 0
Exclamación Descargar varios txt de un servidor ftp

Saludos,
Les comento mi problema.
Resulta que necesito descargar unos ficheros desde un servidor ftp
y eh buscado mucho y lo que logre encontrar solo fue un codigo el cual
extrae los datos de un txt y lo pasa a otro txt al disco del pc.

Me gustaria saber si alguien me puede ayudar a que me descargue todos los archivos txt que se encuentren en dicho servidor ftp, asi poder descargarlos y guardarlos en el disco duro del pc.


El codigo me logea bien y todo eso, pero necesito que me pueda descargar mas de 1 fichero txt.

aca va el codigo si alguien sabe o ha hecho esto antes.








Código ASP:
Ver original
  1. 'Values to use
  2.         Const localFile As String = "C:\EJEMPLOS\hola.txt"
  3.         Const remoteFile As String = "/Prueba/hola.txt"
  4.         Const host As String = "ftp://ftp.xxxxxx.xxxxxx.es/"
  5.         Const username As String = "user"
  6.         Const password As String = "pass"
  7.  
  8.  
  9.         '1. Create a request: must be in ftp://hostname format,
  10.         '   not just ftp.myhost.com
  11.         Dim URI As String = host & remoteFile
  12.         Dim ftp As System.Net.FtpWebRequest = _
  13.             CType(FtpWebRequest.Create(URI), FtpWebRequest)
  14.  
  15.         '2. Set credentials
  16.         ftp.Credentials = New  _
  17.             System.Net.NetworkCredential(username, password)
  18.  
  19.         '3. Settings and action
  20.         ftp.KeepAlive = False
  21.         'we want a binary transfer, not textual data
  22.         ftp.UseBinary = True
  23.         'Define the action required (in this case, download a file)
  24.         ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
  25.  
  26.        '4. If we were using a method that uploads data e.g. UploadFile
  27.         '   we would open the ftp.GetRequestStream here an send the data
  28.  
  29.  
  30.  
  31.         '5. Get the response to the Ftp request and the associated stream
  32.         Using response As System.Net.FtpWebResponse = _
  33.               CType(ftp.GetResponse, System.Net.FtpWebResponse)
  34.             Using responseStream As IO.Stream = response.GetResponseStream
  35.                 'loop to read & write to file
  36.                 Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
  37.                     Dim buffer(2047) As Byte
  38.                     Dim read As Integer = 0
  39.                     Do
  40.                         read = responseStream.Read(buffer, 0, buffer.Length)
  41.                         fs.Write(buffer, 0, read)
  42.                     Loop Until read = 0 'see Note(1)
  43.                     responseStream.Close()
  44.                     fs.Flush()
  45.                     fs.Close()
  46.                 End Using
  47.                 responseStream.Close()
  48.             End Using
  49.             response.Close()
  50.         End Using
  51.  
  52.         '6. Done! the Close happens because ftp goes out of scope
  53.         '   There is no .Close or .Dispose for FtpWebRequest








espero me puedan ayudar.
gracias a todos por su lectura.

Última edición por rockex; 11/01/2011 a las 13:57 Razón: prueba

Etiquetas: ftp, txt, servidores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:14.