Visual Basic.NET - Ayuda con Vb.net y FTP

 
Vista:

Ayuda con Vb.net y FTP

Publicado por EMGA (29 intervenciones) el 09/09/2008 15:26:26
Hola a todos escribia el siguiente post por que necesito quien pueda ayudarme con un problema que tengo lo que sucede esque estoy desarrollando una aplicacion que descarca unos respaldos de una b.d de un servidor por via FTP.

pero por el momento solo tengo un codigo de prueba con el que para probarlo voy a descargar cualquier clase de archivo pero este me saca un error al momento de conectarse con el servidor.

este es el codigo si alguien tiene la manera de mirar el problema que me saca y puede ayudarme a solucionarle selo agradeco de ante mano.

FORM

Imports System.Collections.Generic
Imports Utilities.FTP

Public Class Form1
' When using events, the Chilkat.Ftp2 object must be a class member or global variable.
Dim WithEvents ftp2 As New Chilkat.Ftp2

' Update the progress bar control with the percent done.
Private Sub ftp2_OnFtpPercentDone(ByVal sender As Object, ByVal args As Chilkat.FtpPercentDoneEventArgs) Handles ftp2.OnFtpPercentDone

ProgressBar1.Value = args.PercentDone

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

ftp2.UnlockComponent("Anything for 365-day trial")

ftp2.Hostname = "ftp://ftp.shinranet.com"
ftp2.Username = "USUARIO"
ftp2.Password = "PASWORD"

' EnableEvents must be set to True for events to fire.
ftp2.EnableEvents = True

' Connect to the FTP server and login.
Dim success As Boolean
success = ftp2.Connect()
If (Not success) Then
ftp2.SaveLastError("ftpError.txt")
Exit Sub
End If

' Navigate to the "testing" subdirectory on the ftp server.
success = ftp2.ChangeRemoteDir("testing")
If (Not success) Then
ftp2.SaveLastError("ftpError.txt")
Exit Sub
End If

' Download the file.
' The 1st argument is the remote filename, the 2nd argument
' is the local filename to be created.
success = ftp2.GetFile("big.gif", "bigLocal.gif")
If (Not success) Then
ftp2.SaveLastError("ftpError.txt")
Exit Sub
End If

ftp2.Disconnect()

End Sub


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.zip"
Const host As String = "ftp://ftp.Shinranet.com"
Const username As String = "Usuario"
Const password As String = "Password"

'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

RE:Ayuda con Vb.net y FTP

Publicado por favio (1 intervención) el 16/12/2008 17:28:32
Hola que tal, probaste lo siguiente?
my.computer.network.downloadfile("Dir local", "Dir ftp", "usuario", password")
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ayuda con Vb.net y FTP

Publicado por eotinianor (13 intervenciones) el 28/04/2011 21:48:07
y si quiero descargar todos los archivos de una carpeta, ¿como se hace?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar