From e5b4ec1b0bcecf8b5c398e8fe0e058b29d25a763 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sat, 27 Feb 2016 18:18:40 +0100 Subject: [PATCH] Avoid EPSV after failure --- client_test.go | 14 +------------- ftp.go | 16 +++++++++++----- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/client_test.go b/client_test.go index ac09cd5..34033ca 100644 --- a/client_test.go +++ b/client_test.go @@ -13,15 +13,7 @@ const ( testDir = "mydir" ) -func TestConnPASV(t *testing.T) { - testConn(t, true) -} - -func TestConnEPSV(t *testing.T) { - testConn(t, false) -} - -func testConn(t *testing.T, passive bool) { +func TestConn(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } @@ -31,10 +23,6 @@ func testConn(t *testing.T, passive bool) { t.Fatal(err) } - if passive { - delete(c.features, "EPSV") - } - err = c.Login("anonymous", "anonymous") if err != nil { t.Fatal(err) diff --git a/ftp.go b/ftp.go index db7ac92..10f907c 100644 --- a/ftp.go +++ b/ftp.go @@ -24,10 +24,11 @@ const ( // ServerConn represents the connection to a remote FTP server. type ServerConn struct { - conn *textproto.Conn - host string - timeout time.Duration - features map[string]string + conn *textproto.Conn + host string + timeout time.Duration + features map[string]string + epsvFailed bool } // Entry describes a file and is returned by List(). @@ -226,7 +227,12 @@ func (c *ServerConn) openDataConn() (net.Conn, error) { err error ) - if port, err = c.epsv(); err != nil { + if !c.epsvFailed { + if port, err = c.epsv(); err != nil { + c.epsvFailed = true + } + } + if c.epsvFailed { if port, err = c.pasv(); err != nil { return nil, err }