PDA

View Full Version : [VB2010] - Lista file da FTP


lucausa75
13-10-2011, 08:55
Salve ragazzi,

la routine a sueguire funziona alla perfezione:

Public Function GetFileList(ByVal path As String, ByVal MyList As ListBox) As List(Of String)
Dim retList = New List(Of String)

If (path = Nothing Or path = "") Then
path = "/"
End If

_FtpRequest = CType(WebRequest.Create("ftp://" + _Host + path), FtpWebRequest)
_FtpRequest.Credentials = New NetworkCredential(_UserName, _Password)
_FtpRequest.UsePassive = False 'Is necessary to set the ftp request in passive mode in order to avoid error 227
_FtpRequest.UsePassive = True 'Is necessary to set the ftp request in passive mode in order to avoid error 425
_FtpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
_FtpRequest.EnableSsl = _UseSSL
_FtpRequest.Proxy = Nothing
_FtpResponse = CType(_FtpRequest.GetResponse(), FtpWebResponse)

Dim sr As New IO.StreamReader(_FtpRequest.GetResponse().GetResponseStream())
Dim str As String = sr.ReadLine()
While Not str Is Nothing
If Not str.StartsWith(".") Then
MyList.Items.Add(str)
End If
str = sr.ReadLine()
End While
sr.Close()
sr.Dispose()
sr = Nothing
_FtpRequest = Nothing
Return retList

End Function

però il problema è la proprietà .UsePassive che ho sempre settato a false però in altri casi miserve true ed in particolare:

FALSE==>Per evitare l'errore 227
TRUE==>Per evitare l'errore 425

Mi servirebbe capire come impostare automaticamente questa proprietà in modo da adattarsi all'"uso" ;)

Grazie