diff --git a/client/transfer.go b/client/transfer.go index 41b5d37..bd6892f 100644 --- a/client/transfer.go +++ b/client/transfer.go @@ -17,11 +17,13 @@ func (c *Handler) handlePASV() { var err error portRange := context.Settings.DataPortRange + listenHost := context.Settings.ListenHost + publicHost := context.Settings.PublicHost if portRange != nil { for start := portRange.Start; start < portRange.End; start++ { port := portRange.Start + rand.Intn(portRange.End-portRange.Start) - localAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:"+fmt.Sprintf("%d", port)) + localAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", listenHost, port)) if err != nil { continue } @@ -60,15 +62,8 @@ func (c *Handler) handlePASV() { if c.command == "PASV" { p1 := p.Port / 256 p2 := p.Port - (p1 * 256) - // Provide our external IP address so the ftp client can connect back to us. - ip := context.Settings.PublicHost - // If we don't have an IP address, we can take the one that was used for the current connection. - if ip == "" { - ip = strings.Split(c.conn.LocalAddr().String(), ":")[0] - } - - quads := strings.Split(ip, ".") + quads := strings.Split(publicHost, ".") c.WriteMessage(227, fmt.Sprintf("Entering Passive Mode (%s,%s,%s,%s,%d,%d)", quads[0], quads[1], quads[2], quads[3], p1, p2)) } else { c.WriteMessage(229, fmt.Sprintf("Entering Extended Passive Mode (|||%d|)", p.Port)) diff --git a/context/config.go b/context/config.go index 6734ce4..2d66ba5 100644 --- a/context/config.go +++ b/context/config.go @@ -23,6 +23,7 @@ type Config struct { ListenHost string `yaml:"listen_host"` ListenPort int `yaml:"listen_port"` + PublicHost string `yaml:"public_host"` MaxConnections int `yaml:"max_connections"` BucketName string `yaml:"bucket_name"` Zone string `yaml:"zone"` @@ -76,6 +77,9 @@ func (c *Config) Check() error { // For the automatic value, We let the system decide (0). c.ListenPort = 0 } + if c.PublicHost == "" { + c.PublicHost = "127.0.0.1" + } if c.MaxConnections == 0 { c.MaxConnections = 10000 } diff --git a/context/context.go b/context/context.go index c2bcff9..8251ebf 100644 --- a/context/context.go +++ b/context/context.go @@ -31,7 +31,7 @@ func SetupContext(c *Config) error { Settings = &ServerSettings{ ListenHost: c.ListenHost, ListenPort: c.ListenPort, - PublicHost: c.ListenHost, + PublicHost: c.PublicHost, MaxConnections: c.MaxConnections, DataPortRange: &PortRange{ Start: 6000, diff --git a/qsftp.yaml.example b/qsftp.yaml.example index 2a43a8e..c02709c 100644 --- a/qsftp.yaml.example +++ b/qsftp.yaml.example @@ -14,6 +14,7 @@ zone: pek3a # FTP server settings listen_host: 127.0.0.1 listen_port: 2121 +public_host: 127.0.0.1 max_connections: 128 # Authentication settings