Disable EPSV for tests.
Also disable it for next attempts when it failed.
This commit is contained in:
parent
72154dff87
commit
988909ab28
@ -21,7 +21,7 @@ func TestConnEPSV(t *testing.T) {
|
|||||||
testConn(t, false)
|
testConn(t, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConn(t *testing.T, passive bool) {
|
func testConn(t *testing.T, disableEPSV bool) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping test in short mode.")
|
t.Skip("skipping test in short mode.")
|
||||||
}
|
}
|
||||||
@ -31,8 +31,9 @@ func testConn(t *testing.T, passive bool) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if passive {
|
if disableEPSV {
|
||||||
delete(c.features, "EPSV")
|
delete(c.features, "EPSV")
|
||||||
|
c.disableEPSV = true
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Login("anonymous", "anonymous")
|
err = c.Login("anonymous", "anonymous")
|
||||||
|
26
ftp.go
26
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
|
||||||
|
disableEPSV bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry describes a file and is returned by List().
|
// Entry describes a file and is returned by List().
|
||||||
@ -219,18 +220,27 @@ func (c *ServerConn) pasv() (port int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getDataConnPort returns a port for a new data connection
|
||||||
|
// it uses the best available method to do so
|
||||||
|
func (c *ServerConn) getDataConnPort() (int, error) {
|
||||||
|
if !c.disableEPSV {
|
||||||
|
if port, err := c.epsv(); err == nil {
|
||||||
|
return port, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there is an error, disable EPSV for the next attempts
|
||||||
|
c.disableEPSV = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.pasv()
|
||||||
|
}
|
||||||
|
|
||||||
// openDataConn creates a new FTP data connection.
|
// openDataConn creates a new FTP data connection.
|
||||||
func (c *ServerConn) openDataConn() (net.Conn, error) {
|
func (c *ServerConn) openDataConn() (net.Conn, error) {
|
||||||
var (
|
port, err := c.getDataConnPort()
|
||||||
port int
|
if err != nil {
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if port, err = c.epsv(); err != nil {
|
|
||||||
if port, err = c.pasv(); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return net.DialTimeout("tcp", net.JoinHostPort(c.host, strconv.Itoa(port)), c.timeout)
|
return net.DialTimeout("tcp", net.JoinHostPort(c.host, strconv.Itoa(port)), c.timeout)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user