Use tls.Dialer to be able to use DialContext

This commit is contained in:
Julien Laffaye 2022-08-17 19:35:55 -04:00
parent 45482d097e
commit fa83b53d0e
No known key found for this signature in database
GPG Key ID: 890C3E5C169AE841

16
ftp.go
View File

@ -110,16 +110,20 @@ func Dial(addr string, options ...DialOption) (*ServerConn, error) {
dialFunc := do.dialFunc
if dialFunc == nil {
ctx := do.context
if ctx == nil {
ctx = context.Background()
}
if do.tlsConfig != nil && !do.explicitTLS {
dialFunc = func(network, address string) (net.Conn, error) {
return tls.DialWithDialer(&do.dialer, network, addr, do.tlsConfig)
tlsDialer := &tls.Dialer{
NetDialer: &do.dialer,
Config: do.tlsConfig,
}
return tlsDialer.DialContext(ctx, network, addr)
}
} else {
ctx := do.context
if ctx == nil {
ctx = context.Background()
}
dialFunc = func(network, address string) (net.Conn, error) {
return do.dialer.DialContext(ctx, network, addr)