Salve.
personalmente, nel caso specifico, non ho usato altro che FTPWebRequest...
brutalmente, cannibalizzando del vecchio codice che scrissi tanto tempo fa,
Dim hostName As String = e.HostName.Replace("\", "/")
Dim hostPath As String = e.HostPath.Replace("\", "/")
If Not String.IsNullOrEmpty(hostPath) Then
If hostPath.StartsWith("/") Then hostPath = hostPath.Substring(1)
If Not hostPath.EndsWith("/") Then hostPath &= "/"
Else
If Not hostName.EndsWith("/") Then hostName &= "/"
End If
Dim uploadUrl As String = hostName
Dim newUriPort As UriBuilder = New UriBuilder(uploadUrl)
newUriPort.Port = portNr
uploadUrl = newUriPort.Uri.ToString & hostPath & e.FileName
Dim Request As FtpWebRequest = CType(WebRequest.Create(ourUri), FtpWebRequest)
Request.Method = WebRequestMethods.Ftp.DownloadFile
' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
Request.Proxy = Nothing
Request.Timeout = xxxx
Request.Credentials = New Net.NetworkCredential("user", "Password")
Request.ReadWriteTimeout = xxx
Request.UseBinary = true/false
Request.UsePassive = true/false
Request.KeepAlive = True
Try
Using response As FtpWebResponse = CType(Request.GetResponse, FtpWebResponse)
Using responseStream As Stream = response.GetResponseStream
'loop to read & write to file
Using fs As New FileStream(Path.Combine("LocalPath", "FileName"), FileMode.OpenOrCreate)
Try
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
responseStream.Close()
fs.Flush()
fs.Close()
Catch ex As Exception
'catch error and delete file only partially downloaded
fs.Close()
'delete target file as it's incomplete
Try
File.Delete(Path.Combine(e.LocalPath, e.FileName))
Catch ex1 As Exception
Debug.Write(ex1.Message)
End Try
End Try
End Using
responseStream.Close()
End Using
response.Close()
End Using
Catch ex As Exception
Debug.Write(ex.Message)
End Try
Request = Nothing
non ho guardato il tuo codice... troppo pigro a quest'ora
salutoni omnia
--
Andrea