fix dial stuck when connect to tls ftp without tls configuration

Signed-off-by: Cytown <cytown@gmail.com>
This commit is contained in:
Cytown 2024-06-07 16:35:45 +08:00
parent 4edb16bfcd
commit 1edcd4b3ca
No known key found for this signature in database
GPG Key ID: F3D7B024C3EB5CEE

19
ftp.go
View File

@ -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 {