Avoid EPSV after failure
This commit is contained in:
parent
0e072be722
commit
e5b4ec1b0b
@ -13,15 +13,7 @@ const (
|
|||||||
testDir = "mydir"
|
testDir = "mydir"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConnPASV(t *testing.T) {
|
func TestConn(t *testing.T) {
|
||||||
testConn(t, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnEPSV(t *testing.T) {
|
|
||||||
testConn(t, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testConn(t *testing.T, passive bool) {
|
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
@ -31,10 +23,6 @@ func testConn(t *testing.T, passive bool) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if passive {
|
|
||||||
delete(c.features, "EPSV")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.Login("anonymous", "anonymous")
|
err = c.Login("anonymous", "anonymous")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
6
ftp.go
6
ftp.go
@ -28,6 +28,7 @@ type ServerConn struct {
|
|||||||
host string
|
host string
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
features map[string]string
|
features map[string]string
|
||||||
|
epsvFailed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry describes a file and is returned by List().
|
// Entry describes a file and is returned by List().
|
||||||
@ -226,7 +227,12 @@ func (c *ServerConn) openDataConn() (net.Conn, error) {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if !c.epsvFailed {
|
||||||
if port, err = c.epsv(); err != nil {
|
if port, err = c.epsv(); err != nil {
|
||||||
|
c.epsvFailed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.epsvFailed {
|
||||||
if port, err = c.pasv(); err != nil {
|
if port, err = c.pasv(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user