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
| Dim fwr As Net.FtpWebRequest = Net.FtpWebRequest.Create(dossier_ftp)
fwr.Credentials = New Net.NetworkCredential(user, mdp)
fwr.Method = Net.WebRequestMethods.Ftp.ListDirectory
Dim sr As New StreamReader(fwr.GetResponse().GetResponseStream(), System.Text.Encoding.UTF7)
Dim str As String = sr.ReadLine()
While Not str Is Nothing
Dim size As Net.FtpWebRequest = System.Net.WebRequest.Create(dossier_ftp & "/" & str)
size.Method = Net.WebRequestMethods.Ftp.GetFileSize
size.Credentials = New Net.NetworkCredential(user, mdp)
Dim sizer As Net.FtpWebResponse
Try
sizer = DirectCast(size.GetResponse, Net.FtpWebResponse)
Catch ex As Exception
'La demande passe en recursif on rappel donc notre fonction avec le nouveau dossier
If rec = "o" Then
ftp(dlocal & "\" & str, user, mdp, dftp & "/" & str, recursif)
End If
GoTo next_ligne
End Try
Dim clsRequest As Net.FtpWebRequest = System.Net.WebRequest.Create(dossier_ftp & "/" & str)
clsRequest.Method = Net.WebRequestMethods.Ftp.DownloadFile
clsRequest.Credentials = New Net.NetworkCredential(user, mdp)
Dim response As Net.FtpWebResponse = DirectCast(clsRequest.GetResponse(), Net.FtpWebResponse)
Dim responseStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(responseStream)
Dim di As New DirectoryInfo(dossier_local)
If di.Exists = False Then
di.Create()
End If
Console.WriteLine(dossier_local & "\" & str)
IO.File.WriteAllText(dossier_local & "\" & str, reader.ReadToEnd)
next_ligne:
str = sr.ReadLine()
End While
sr.Close()
sr = Nothing
fwr = Nothing
End
'err:
' If Err.Number = "550" Then
'MsgBox("Impossible d'accéder à la ressource demandé." & vbCrLf & "Merci de vérifier vos informations de connexions", MsgBoxStyle.Critical)
'End If
End Function |
Partager