-
-
Notifications
You must be signed in to change notification settings - Fork 660
/
ConnectFTPSCertificate.vb
36 lines (32 loc) · 1.14 KB
/
ConnectFTPSCertificate.vb
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
Imports System
Imports System.Net
Imports System.Threading
Imports System.Threading.Tasks
Imports FluentFTP
Namespace Examples
Friend Module ConnectFTPSCertificateExample
Sub ConnectFTPSCertificate()
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest")
conn.Config.EncryptionMode = FtpEncryptionMode.Explicit
AddHandler conn.ValidateCertificate, New FtpSslValidation(AddressOf OnValidateCertificate)
conn.Connect()
End Using
End Sub
Async Function ConnectFTPSCertificateAsync() As Task
Dim token = New CancellationToken()
Using conn = New AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")
conn.Config.EncryptionMode = FtpEncryptionMode.Explicit
AddHandler conn.ValidateCertificate, New FtpSslValidation(AddressOf OnValidateCertificate)
Await conn.Connect(token)
End Using
End Function
Private Sub OnValidateCertificate(ByVal control As FtpClient, ByVal e As FtpSslValidationEventArgs)
If e.PolicyErrors <> System.Net.Security.SslPolicyErrors.None Then
' invalid cert, do you want to accept it?
' e.Accept = True
Else
e.Accept = True
End If
End Sub
End Module
End Namespace