-
Notifications
You must be signed in to change notification settings - Fork 5
/
parameters.go
106 lines (98 loc) · 2.22 KB
/
parameters.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package sftps
type ftpParameters struct {
host string
port int
listenPort int
user string
pass string
passive bool
keepAlive bool
secure bool
alwaysTrust bool
secureMode int
rootCA string
cert string
key string
}
type sftpParameters struct {
host string
port int
user string
pass string
useKey bool
privateKey string
usePassphrase bool
passphrase string
keepAlive bool
}
func NewSftpParameters(host string, port int, user string, pass string, keepAlive bool) *sftpParameters {
if host == "" || user == "" {
panic("Invalid parameter were bound.")
}
param := &sftpParameters {
host: host,
port: port,
user: user,
pass: pass,
useKey: false,
privateKey: "",
usePassphrase: false,
passphrase: "",
keepAlive: keepAlive,
}
return param
}
func (param *sftpParameters) Keys(privateKey string, usePassphrase bool, passphrase string) {
param.useKey = true
if usePassphrase {
if passphrase == "" {
panic("The passphrase must not be empty when specified true to usePassphrase.")
}
param.usePassphrase = true
param.passphrase = passphrase
}
}
func NewFtpParameters(host string, port int, user string, pass string, keepalive bool) *ftpParameters {
if host == "" || user == "" || pass == "" {
panic("Invalid parameter were bound.")
}
param := &ftpParameters{
host: host,
port: port,
listenPort: 0,
user: user,
pass: pass,
passive: true,
keepAlive: keepalive,
secure: false,
alwaysTrust: false,
secureMode: EXPLICIT,
rootCA: "",
cert: "",
key: "",
}
return param
}
func (param *ftpParameters) ActiveMode(actvPort int) {
param.passive = false
param.listenPort = actvPort
}
func (param *ftpParameters) Secure(skipVerify bool) {
param.secure = true
param.alwaysTrust = skipVerify
}
func (param *ftpParameters) Certs(rca string, cert string, key string) {
param.secure = true
param.rootCA = rca
param.cert = cert
param.key = key
}
func (param *ftpParameters) Implicit(port int) {
param.secure = true
param.secureMode = IMPLICIT
if port == 0 {
param.port = 990
} else {
param.port = port
}
}