Visual Basic.NET - ayuda con busqueda de archivos

 
Vista:

ayuda con busqueda de archivos

Publicado por EMGA (29 intervenciones) el 10/09/2008 15:52:43
Hola gente necesito saber quien me puede ayudar con una duda que tengo.
quisiera saber que linea de codigo debo usar para buscar un archivo que tenga cualquier nombre y cualquier extencion en un programa que busaca archivos en un servidor ftp

por ejemple tengo este cod pero me gustaria saber eso con base al codigo o saber si el codigo es el correcto. por que me presenta un error que dice asi :

The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Este es el cod:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'EXAMPLE OF HOW TO USE FtpWebRequest

'Values to use
Const localFile As String = "C:\file.bin"
Const remoteFile As String = "/ftpfile.bin"
Const host As String = "ftp://198.63.53.123"
Const username As String = "malvin"
Const password As String = "malvin02488420"

'Create a request
Dim URI As New System.Uri(host & remoteFile)
Dim ftp As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(URI), System.Net.FtpWebRequest)
'Set the credentials
ftp.Credentials = New System.Net.NetworkCredential(username, password)
'Turn off KeepAlive (will close connection on completion)
ftp.KeepAlive = False
'we want a binary
ftp.UseBinary = True
'Define the action required (in this case, download a file)
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

'If we were using a method that uploads data e.g. UploadFile
'we would open the ftp.GetRequestStream here an send the data

'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
End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder