fix dial stuck when connect to tls ftp without tls configuration
Signed-off-by: Cytown <cytown@gmail.com>
This commit is contained in:
parent
4edb16bfcd
commit
1edcd4b3ca
19
ftp.go
19
ftp.go
@ -161,11 +161,30 @@ func Dial(addr string, options ...DialOption) (*ServerConn, error) {
|
||||
host: remoteAddr.IP.String(),
|
||||
}
|
||||
|
||||
readyChan := make(chan error, 1)
|
||||
go func(c *ServerConn) {
|
||||
_, _, err = c.conn.ReadResponse(StatusReady)
|
||||
if err != nil {
|
||||
_ = c.Quit()
|
||||
readyChan <- err
|
||||
return
|
||||
}
|
||||
readyChan <- nil
|
||||
}(c)
|
||||
|
||||
readyTimeer := time.NewTimer(do.dialer.Timeout)
|
||||
select {
|
||||
case err = <-readyChan:{
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
case <-readyTimeer.C:{
|
||||
return nil, errors.New("Timeout waiting for server to be ready, maybe need TLS?")
|
||||
}
|
||||
}
|
||||
close(readyChan)
|
||||
|
||||
if do.explicitTLS {
|
||||
if err := c.authTLS(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user