Avoid EPSV after failure

This commit is contained in:
Julian Kornberger 2016-02-27 18:18:40 +01:00
parent 0e072be722
commit e5b4ec1b0b
2 changed files with 12 additions and 18 deletions

View File

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

16
ftp.go
View File

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