Skip to content

Commit

Permalink
Resolve publicHost processing incorrectly
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Apr 27, 2017
1 parent dcaf306 commit c0815c5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
13 changes: 4 additions & 9 deletions client/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions context/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions qsftp.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0815c5

Please sign in to comment.