FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
482 stars 163 forks source link

Provide configurable IP address when using NAT #54

Closed fubar-coder closed 5 years ago

fubar-coder commented 5 years ago

In case of NAT, the local IP address differs from the public IP address. We must provide a way to make this configurable.

avonheimburg commented 5 years ago

Already done and already part of pull request #50, called "PasvAddress'.

avonheimburg commented 5 years ago

See FtpServerOptions.cs

fubar-coder commented 5 years ago

Yes, you're right. It's the PasvExternalAddress option. I'll leave this open, because I'd like to change this a little bit to support the special case where a service might have multiple "public" IP addresses (e.g. IPv4, IPv6 and available over multiple network interfaces behind firewalls, etc...)

avonheimburg commented 5 years ago

Hm. How do you propose going about that? Map interface IPs to public IPs?

fubar-coder commented 5 years ago

I'd just pass the local and remote IPs to a service to get the public IP. This should allow a configuration on a per-network-interface basis and should also be able to handle both IPv4 and IPv6.

EDIT: The local IP should be enough to identify the network interface.

fubar-coder commented 5 years ago

You can find my proposed solution in the release/3.0 branch. It's not published yet.

The idea is implemented using an IPasvAddressResolver service. This service gets the connection and returns PasvListenerOptions. This allows the specification of a public IP address and IP port range depending on the local IP address (network interface). This also allows us to return an IPv6 address when the user connects via IPv6.

There is a standard implementation called SimplePasvAddressResolver which can be configured using SimplePasvOptions.