gofmt ftp.go
This commit is contained in:
parent
816272713b
commit
1b161dcaad
86
ftp.go
86
ftp.go
@ -153,39 +153,39 @@ func (c *ServerConn) epsv() (port int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// pasv issues an "PASV" command to get a port number for a data connection.
|
// pasv issues a "PASV" command to get a port number for a data connection.
|
||||||
func (c *ServerConn) pasv() (port int, err error) {
|
func (c *ServerConn) pasv() (port int, err error) {
|
||||||
_, line, err := c.cmd(StatusPassiveMode, "PASV")
|
_, line, err := c.cmd(StatusPassiveMode, "PASV")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
|
// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
|
||||||
start := strings.Index(line, "(")
|
start := strings.Index(line, "(")
|
||||||
end := strings.LastIndex(line, ")")
|
end := strings.LastIndex(line, ")")
|
||||||
if start == -1 || end == -1 {
|
if start == -1 || end == -1 {
|
||||||
err = errors.New("Invalid EPSV response format")
|
err = errors.New("Invalid EPSV response format")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to split the response string
|
// We have to split the response string
|
||||||
pasvData := strings.Split(line[start+1 : end], ",")
|
pasvData := strings.Split(line[start+1:end], ",")
|
||||||
// Let's compute the port number
|
// Let's compute the port number
|
||||||
portPart1, err1 := strconv.Atoi(pasvData[4])
|
portPart1, err1 := strconv.Atoi(pasvData[4])
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
err = err1
|
err = err1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
portPart2, err2 := strconv.Atoi(pasvData[5])
|
portPart2, err2 := strconv.Atoi(pasvData[5])
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err = err2
|
err = err2
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recompose port
|
// Recompose port
|
||||||
port = portPart1 * 256 + portPart2
|
port = portPart1*256 + portPart2
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// openDataConn creates a new FTP data connection.
|
// openDataConn creates a new FTP data connection.
|
||||||
@ -193,26 +193,25 @@ func (c *ServerConn) pasv() (port int, err error) {
|
|||||||
// Currently, only EPSV is implemented but a fallback to PASV, and to a lesser
|
// Currently, only EPSV is implemented but a fallback to PASV, and to a lesser
|
||||||
// extent, PORT should be added.
|
// extent, PORT should be added.
|
||||||
func (c *ServerConn) openDataConn() (net.Conn, error) {
|
func (c *ServerConn) openDataConn() (net.Conn, error) {
|
||||||
var port int
|
var port int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// If features contains nat6 or EPSV => EPSV
|
// If features contains nat6 or EPSV => EPSV
|
||||||
// else -> PASV
|
// else -> PASV
|
||||||
_,nat6Supported := c.features["nat6"];
|
_, nat6Supported := c.features["nat6"]
|
||||||
_,epsvSupported := c.features["EPSV"];
|
_, epsvSupported := c.features["EPSV"]
|
||||||
if nat6Supported || epsvSupported {
|
if nat6Supported || epsvSupported {
|
||||||
port, err = c.epsv()
|
port, err = c.epsv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
port, err = c.pasv()
|
port, err = c.pasv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build the new net address string
|
// Build the new net address string
|
||||||
addr := fmt.Sprintf("%s:%d", c.host, port)
|
addr := fmt.Sprintf("%s:%d", c.host, port)
|
||||||
|
|
||||||
@ -467,4 +466,3 @@ func (r *response) Close() error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user