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'Values to use
Const localFile As String = "C:\EJEMPLOS\hola.txt"
Const remoteFile As String = "/Prueba/hola.txt"
Const host As String = "ftp://ftp.xxxxxx.xxxxxx.es/"
Const username As String = "user"
Const password As String = "pass"
'1. Create a request: must be in ftp://hostname format,
' not just ftp.myhost.com
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)
'2. Set credentials
ftp.Credentials = New _
System.Net.NetworkCredential(username, password)
'3. Settings and action
ftp.KeepAlive = False
'we want a binary transfer, not textual data
ftp.UseBinary = True
'Define the action required (in this case, download a file)
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
'4. If we were using a method that uploads data e.g. UploadFile
' we would open the ftp.GetRequestStream here an send the data
'5. Get the response to the Ftp request and the associated stream
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
'loop to read & write to file
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0 'see Note(1)
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
'6. Done! the Close happens because ftp goes out of scope
' There is no .Close or .Dispose for FtpWebRequest
espero me puedan ayudar.
gracias a todos por su lectura.