-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConnectFTPSGnuTLS.cs
91 lines (68 loc) · 2.58 KB
/
ConnectFTPSGnuTLS.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentFTP;
using FluentFTP.Client.BaseClient;
using FluentFTP.GnuTLS;
using FluentFTP.GnuTLS.Enums;
namespace Examples {
internal static class ConnectFTPSGnuTLSExample {
public static void ConnectFTPSCertificate() {
using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
// enable GnuTLS streams for FTP client
conn.Config.CustomStream = typeof(GnuTlsStream);
conn.Config.CustomStreamConfig = new GnuConfig() {
LogLevel = 1,
// sample setting to use the default security suite
SecuritySuite = GnuSuite.Normal,
// sample setting to include all TLS protocols except for TLS 1.0 and TLS 1.1
SecurityOptions = new List<GnuOption> {
new GnuOption(GnuOperator.Include, GnuCommand.Protocol_All),
new GnuOption(GnuOperator.Exclude, GnuCommand.Protocol_Tls10),
new GnuOption(GnuOperator.Exclude, GnuCommand.Protocol_Tls11),
},
// no profile required
SecurityProfile = GnuProfile.None,
// sample special flags (this is not normally required)
AdvancedOptions = new List<GnuAdvanced> {
GnuAdvanced.CompatibilityMode
},
HandshakeTimeout = 5000,
};
// connect using Explicit FTPS with TLS 1.3
conn.Config.EncryptionMode = FtpEncryptionMode.Explicit;
conn.Connect();
}
}
public static async Task ConnectFTPSCertificateAsync() {
var token = new CancellationToken();
using (var conn = new AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")) {
// enable GnuTLS streams for FTP client
conn.Config.CustomStream = typeof(GnuTlsStream);
conn.Config.CustomStreamConfig = new GnuConfig() {
LogLevel = 1,
// sample setting to use the default security suite
SecuritySuite = GnuSuite.Normal,
// sample setting to include all TLS protocols except for TLS 1.0 and TLS 1.1
SecurityOptions = new List<GnuOption> {
new GnuOption(GnuOperator.Include, GnuCommand.Protocol_All),
new GnuOption(GnuOperator.Exclude, GnuCommand.Protocol_Tls10),
new GnuOption(GnuOperator.Exclude, GnuCommand.Protocol_Tls11),
},
// no profile required
SecurityProfile = GnuProfile.None,
// sample special flags (this is not normally required)
AdvancedOptions = new List<GnuAdvanced> {
GnuAdvanced.CompatibilityMode
},
HandshakeTimeout = 5000,
};
// connect using Explicit FTPS with TLS 1.3
conn.Config.EncryptionMode = FtpEncryptionMode.Explicit;
await conn.Connect(token);
}
}
}
}