diff --git a/ftp.go b/ftp.go index 02136ae..982916d 100644 --- a/ftp.go +++ b/ftp.go @@ -571,10 +571,14 @@ func (c *ServerConn) openDataConn() (net.Conn, error) { } addr := net.JoinHostPort(host, strconv.Itoa(port)) + var dialFunc = c.options.dialer.Dial if c.options.dialFunc != nil { - return c.options.dialFunc("tcp", addr) + dialFunc = c.options.dialFunc + } + conn, err := dialFunc("tcp", addr) + if err != nil { + return nil, err } - if c.options.tlsConfig != nil { // We don't use tls.DialWithDialer here (which does Dial, create // the Client and then do the Handshake) because it seems to @@ -588,15 +592,9 @@ func (c *ServerConn) openDataConn() (net.Conn, error) { // won't have been called. This is done in StorFrom(). // // See: https://github.com/jlaffaye/ftp/issues/282 - conn, err := c.options.dialer.Dial("tcp", addr) - if err != nil { - return nil, err - } - tlsConn := tls.Client(conn, c.options.tlsConfig) - return tlsConn, nil + conn = tls.Client(conn, c.options.tlsConfig) } - - return c.options.dialer.Dial("tcp", addr) + return conn, nil } // cmd is a helper function to execute a command and check for the expected FTP @@ -656,7 +654,7 @@ func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...inter // Type switches the transfer mode for the connection. func (c *ServerConn) Type(transferType TransferType) (err error) { - _, _, err = c.cmd(StatusCommandOK, "TYPE "+string(transferType)) + _, _, err = c.cmd(StatusCommandOK, "TYPE %s", transferType) return err } diff --git a/go.mod b/go.mod index d0e061a..7574093 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/jlaffaye/ftp +module github.com/medianexapp/ftp -go 1.17 +go 1.24 require ( github.com/hashicorp/go-multierror v1.1.1 diff --git a/go.sum b/go.sum index 51a624a..2b0d505 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= @@ -7,17 +6,9 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=