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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
Public Function GetListNameFiles(ByVal URI_Server As String, ByVal Login As String, ByVal Password As String) As String()
'Instanciation d'une URI qui va contenir le chemin source
Dim My_URI_Server As New System.Uri(URI_Server)
Dim Array_Of_NameFiles() As String
Dim My_StreamReader As StreamReader = Nothing
' Vérification de la validité de l'URI du fichier sur le serveur FTP
If Not (My_URI_Server.Scheme = Uri.UriSchemeFtp) Then
MsgBox("L'URI du serveur est invalide.")
Return Nothing
Else
Try
' Création de la requête de récupération de la liste des fichiers
Dim My_Request_To_GetListNameFiles As FtpWebRequest = CType(WebRequest.Create(My_URI_Server), FtpWebRequest)
My_Request_To_GetListNameFiles.Method = WebRequestMethods.Ftp.ListDirectory
'Définition du compte FTP
Dim MyAccountFTP As New NetworkCredential(Login, Password)
My_Request_To_GetListNameFiles.Credentials = MyAccountFTP
'Récupération de la liste de fichiers
Dim My_Response_To_GetListNameFiles As FtpWebResponse = CType(My_Request_To_GetListNameFiles.GetResponse, FtpWebResponse)
' Placement du flux provenant du serveur dans un streamreader
My_StreamReader = New StreamReader(My_Response_To_GetListNameFiles.GetResponseStream, System.Text.Encoding.Default)
Dim Current_Line As String
Current_Line = My_StreamReader.ReadLine
While Current_Line IsNot Nothing
If Current_Line.EndsWith(".RAC", StringComparison.OrdinalIgnoreCase) Then
If Array_Of_NameFiles Is Nothing Then
ReDim Preserve Array_Of_NameFiles(0)
Else
ReDim Preserve Array_Of_NameFiles(Array_Of_NameFiles.Length)
End If
Array_Of_NameFiles(Array_Of_NameFiles.Length - 1) = Current_Line
End If
Current_Line = My_StreamReader.ReadLine
End While
My.Computer.Network.UploadFile("C:\TEST.TXT", "ftp://MCA:123@172.21.8.7/TEST.TXT")
My_Response_To_GetListNameFiles.Close()
Return Array_Of_NameFiles
Catch ex As Exception
' Garder la trace dans le fichier Log
MsgBox(ex.Message)
Return Nothing
Finally
' Fermeture des différents flux utilisés
If My_StreamReader IsNot Nothing Then
My_StreamReader.Close()
End If
End Try
End If
End Function |
Partager