Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using server IP as IP for passive mode in case of PASV connection error #305

Open
zlodes opened this issue Jan 12, 2023 · 5 comments
Open
Labels
accepted Accepted issue feature A feature request

Comments

@zlodes
Copy link

zlodes commented Jan 12, 2023

Hi!

Faced this error while working with bad-configured third-party FTP server...

> PASV
< 227 Entering Passive Mode (172,19,192,40,204,178).
dial tcp 172.19.192.40:53441: connect: no route to host

Logs from connection to the same server in FileZilla:

...
Server sent passive reply with unroutable address. Using server address instead.
...

It would be better to have the similar behavior.
May be implemented as a new DialOption.

@MattBrittan
Copy link

The workaround I'm currently using for this is as follows (it stores the address used for the initial connection and then just reuses that for any further connections). This is quite a common problem where FTP servers are behind NAT.

var d net.Dialer
var firstHost string
dialFunc = func(network, address string) (net.Conn, error) {
	host, port, err := net.SplitHostPort(address)
	if err != nil {
		return nil, fmt.Errorf("ftp.Open: Failed to split address %s: %w", address, err)
	}
	if len(firstHost) == 0 {
		firstHost = host
	}
	return d.DialContext(ctx, "tcp", net.JoinHostPort(firstHost, port))
}
c, err := ftp.Dial(ftpUrl.Host, ftp.DialWithContext(ctx), ftp.DialWithDialFunc(dialFunc))

@zlodes
Copy link
Author

zlodes commented Jan 23, 2023

@MattBrittan thanks!
Did the same and it works fine. But seems that it have to be implemented as builtin feature.

@jlaffaye jlaffaye added accepted Accepted issue feature A feature request labels Jan 24, 2023
@tgulacsi
Copy link
Contributor

AFAIS #349 solved this.

@MattBrittan
Copy link

@tgulacsi that should fix some uses; in my case all of the addresses are private so the isBogusDataIP() would return false (and the fix would not be applied).

@tgulacsi
Copy link
Contributor

@MattBrittan sorry, I've missed that the server has private IP address.
Then your solution is the most straightforward.
Maybe documenting it would be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Accepted issue feature A feature request
Projects
None yet
Development

No branches or pull requests

4 participants