SplitHostPort before connecting to the remote.
This, way, we dont have to cleanup the tcp connection if SplitHostPort fails.
This commit is contained in:
parent
aae10f216b
commit
e987451f99
10
ftp.go
10
ftp.go
@ -59,6 +59,11 @@ func Dial(addr string) (*ServerConn, error) {
|
||||
// It is generally followed by a call to Login() as most FTP commands require
|
||||
// an authenticated user.
|
||||
func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tconn, err := net.DialTimeout("tcp", addr, timeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -66,11 +71,6 @@ func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
||||
|
||||
conn := textproto.NewConn(tconn)
|
||||
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
c := &ServerConn{
|
||||
conn: conn,
|
||||
host: host,
|
||||
|
Loading…
Reference in New Issue
Block a user