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
| Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Module Module1
Sub Main()
Console.WriteLine("tentative de connexion")
Dim ftps As FtpWebRequest = Nothing
ConnectFTPS(ftps)
Console.WriteLine("fin")
Console.ReadLine()
End Sub
'Private Function CertificateValidationCallBack(sender As Object, certificate As System.Security.Cryptography.X509Certificates.X509Certificate, chain As System.Security.Cryptography.X509Certificates.X509Chain, sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
' ' If the certificate is a valid, signed certificate, return true.
' If sslPolicyErrors = System.Net.Security.SslPolicyErrors.None Then
' Return True
' End If
' ' If there are errors in the certificate chain, look at each error to determine the cause.
' If (sslPolicyErrors And System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) <> 0 Then
' If chain IsNot Nothing AndAlso chain.ChainStatus IsNot Nothing Then
' For Each status As System.Security.Cryptography.X509Certificates.X509ChainStatus In chain.ChainStatus
' If (certificate.Subject = certificate.Issuer) AndAlso (status.Status = System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot) Then
' ' Self-signed certificates with an untrusted root are valid.
' Continue For
' Else
' If status.Status <> System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError Then
' ' If there are any other errors in the certificate chain, the certificate is invalid,
' ' so the method returns false.
' Return False
' End If
' End If
' Next
' End If
' ' When processing reaches this line, the only errors in the certificate chain are
' ' untrusted root errors for self-signed certificates. These certificates are valid
' ' for default Exchange Server installations, so return true.
' Return True
' Else
' ' In all other cases, return false.
' Return False
' End If
'End Function
Private Sub ConnectFTPS(ByRef ftps As FtpWebRequest)
Try
ServicePointManager.ServerCertificateValidationCallback = Function(obj As Object, certificate As X509Certificate, chain As X509Chain, errors As SslPolicyErrors) True
ftps = DirectCast(FtpWebRequest.Create("ftp://ftps.monserveur.be"), FtpWebRequest)
ftps.Method = WebRequestMethods.Ftp.DownloadFile
ftps.Credentials = New NetworkCredential("XXXX", "XXXX")
ftps.Proxy = GlobalProxySelection.GetEmptyWebProxy
ftps.EnableSsl = True
Dim response As WebResponse = ftps.GetResponse
Console.WriteLine(response.ContentLength.ToString)
Catch ex As WebException
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub ListFTPS()
End Sub
End Module |
Partager