SplitHostPort before connecting to the remote.

This, way, we dont have to cleanup the tcp connection if SplitHostPort fails.
This commit is contained in:
Julien Laffaye 2015-08-18 19:00:56 +02:00
parent aae10f216b
commit e987451f99

10
ftp.go
View File

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