1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Public Function ListDirectory(ByRef pPath As String, ByRef pFtpConnection As ICredentials) As String()
Dim streamReader As StreamReader = Nothing
Try
' Création de la requête de récupération de la liste des fichiers
Dim maRequeteListe As FtpWebRequest = CType(WebRequest.Create(pPath), FtpWebRequest)
maRequeteListe.Method = WebRequestMethods.Ftp.ListDirectoryDetails
maRequeteListe.Credentials = pFtpConnection
' Récupération de la liste de fichiers
Dim maResponseListe As FtpWebResponse = CType(maRequeteListe.GetResponse, FtpWebResponse)
' Placement du flux provenant du serveur dans un streamreader
streamReader = New StreamReader(maResponseListe.GetResponseStream, streamReader.CurrentEncoding())
' Lecture du stream reader
Dim listeBrute As String = streamReader.ReadToEnd
Dim separateur() As String = {vbLf}
Return listeBrute.Split(separateur, StringSplitOptions.RemoveEmptyEntries)
Catch ex As Exception
Console.WriteLine(ex.Message)
Return Nothing
Finally
If streamReader IsNot Nothing Then
streamReader.Close()
End If
End Try
End Function |
Partager