In Vb.net :
Ho realizzato una procedura per fare il download da un FTP con ftp, user e password definito come da esempio associato.
Mi da Un errore quando arriva a responseFTP e mi dice :
URI richiesto non valido per questo FTP.
grazie dell'aiuto.
codice:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sourceFile As String
sourceFile = "ftp://multidata-it.com"
' ----- Initiate the download.
DownloadViaFTP(sourceFile, "utenteftp", "gilda")
End Sub
Private Sub DownloadViaFTP(ByVal sourceFile As String, _
ByVal userName As String, ByVal password As String)
' ----- Download the specified file via FTP and save
' it in the application's directory.
Dim readBuffer(4095) As Byte
Dim count As Integer
Dim requestFile As System.Net.FtpWebRequest
Dim responseFTP As System.Net.FtpWebResponse
Dim responseStream As IO.Stream
Dim outFile As IO.FileStream
Dim destinationFile As String = _
Application.StartupPath & "\perro.jpg"
' ----- Get the output location.
destinationFile = My.Computer.FileSystem.CombinePath( _
My.Application.Info.DirectoryPath, _
My.Computer.FileSystem.GetName(sourceFile))
' ----- Connect to the file on the FTP site.
requestFile = CType(System.Net.FtpWebRequest.Create( _
sourceFile), System.Net.FtpWebRequest)
requestFile.Credentials = New _
System.Net.NetworkCredential(userName, password)
requestFile.KeepAlive = False
requestFile.UseBinary = True
requestFile.Method = _
System.Net.WebRequestMethods.Ftp.DownloadFile
' ----- Open a transmission channel for the file content.
'****************************************************************************
responseFTP = CType(requestFile.GetResponse, System.Net.FtpWebResponse)
'******************************************************************************
' a questo punto mi da :URI richiesto non valido per questo comando FTP.
'
'******************************************************************************
responseStream = responseFTP.GetResponseStream
outFile = New IO.FileStream(destinationFile, IO.FileMode.Create)
' ----- Save the content to the output file block by block.
Do
count = responseStream.Read(readBuffer, 0, _
readBuffer.Length)
outFile.Write(readBuffer, 0, count)
Loop Until count = 0
' ----- Cleanup.
responseStream.Close()
outFile.Flush()
outFile.Close()
responseFTP.Close()
MsgBox("File downloaded!" & vbNewLine & sourceFile)
End Sub
End Class