Mark Williams 14 Posted June 2, 2020 I am trying to create a FTP server for the first time using TIDFTPServer. I have dropped a TFTPServer onto a form and changed properties only as follows: Active = True Bindings = < item IP = '**.**.***.***' Port = 21 end> ReuseSocket = rsTrue If I set the IP address as the external ip address for the server I get an EIDCouldNotBindSocket error and it advises that "Address and port are already in use" when I try to start it. I don't get this problem if I change the IP address to the server's local address (192.168.0.12). Should the IP address always be set to the local IP? I've noticed that IDFTP has an ExternalP property and also ServerHOST property. There is help on the ExternalIP property, but no on the ServerHOST property. Would I be right in assuming these properties are used for external connections to the FTP server rather than anything in the FTPServer's settings? With respect to the ExternalIP address this also seems to require setting of the DataPort. I have tried connecting setting ExternalIP to the relevant IP address and DataPort to 21. Host is blank. When I try to connect I get an error message telling me a Host is required. I've tried setting Host to the external IP and also ServerHost, but either I get Host required error or time out. Share this post Link to post
Remy Lebeau 1436 Posted June 2, 2020 7 hours ago, Mark Williams said: If I set the IP address as the external ip address for the server I get an EIDCouldNotBindSocket error and it advises that "Address and port are already in use" when I try to start it. I don't get this problem if I change the IP address to the server's local address (192.168.0.12). Should the IP address always be set to the local IP? Yes. You cannot bind to an IP that does not belong to the local device that your server is running on. Alternatively, you can bind to '0.0.0.0' to listen on all local IPv4 addresses with a single socket (use '::0' for IPv6). 7 hours ago, Mark Williams said: I've noticed that IDFTP has an ExternalP property and also ServerHOST property. The TIdFTP.ExternalIP property is for use with active-mode file transfers when the FTP session passes through a proxy/router. In active mode, an FTP client has to open a listening socket to receive an inbound TCP connection from the FTP server. As such, it needs to tell the FTP server which IP to connect to, which can't be the local IP when the client is running behind a proxy/router. The TIdFTP.ServerHOST property is used with virtual FTP server hosting, it has nothing to do with file transfers. An FTP server can host multiple sites on the same server IP. So, to differentiate which site an FTP client wants to access, it must send a HOST command to the FTP server. When the TIdFTP.UseHOST property is True, TIdFTP sends the HOST command before performing user authentication. If the TIdFTP.ServerHOST property is blank, the TIdFTP.Host property is used. TIdFTPServer has an OnHostCheck event, and a TIdFTPServerContext.Host property, for handling HOST commands from clients. 7 hours ago, Mark Williams said: Would I be right in assuming these properties are used for external connections to the FTP server rather than anything in the FTPServer's settings? Only the TIdFTP.ExternalIP property deals with file transfers. The TIdFTP.ServerHOST property has nothing to do with that. 7 hours ago, Mark Williams said: With respect to the ExternalIP address this also seems to require setting of the DataPort. The TIdFTP.DataPort property is the local port that TIdFTP will listen on, and the FTP server will connect to, for active-mode transfers. If it is 0 (the default), an available random ephemeral port will be chosen by the OS. If TIdFTP is running behind a proxy/router, you need to set the TIdFTP.ExternalIP property to the proxy/router's public IP, and enable Port Forwarding on your proxy/router to forward inbound traffic from the router's public IP/DataPort to TIdFTP's listening Binding.IP/DataPort. If TIdFTPServer is running behind a proxy/router, you don't need to set the TIdFTP.ExternalIP (unless TIdFTP is also behind a proxy/router), but you do need to enable Port Forwarding on your server's proxy/router to forward inbound traffic from the router's public IP/Port to TIdFTPServer's listening Binding.IP/Port (not DataPort), as well as port forwarding for any ports you setup in TIdFTPServer's DefaultDataPort or PASVBoundPort(Min|Max) properties. 7 hours ago, Mark Williams said: Host is blank. When I try to connect I get an error message telling me a Host is required. The TIdFTP.Host property is the hostname/IP that TIdFTP will connect to when you call TIdFTP.Connect(), so it can't be blank. 7 hours ago, Mark Williams said: I've tried setting Host to the external IP and also ServerHost, but either I get Host required error or time out. Having TIdFTP connect to the proxy/router's public IP will not work, since there is no FTP server running at that IP. That is merely the proxy/router's public IP to the outside world. The TIdFTP.ServerHOST property has no effect on where TIdFTP.Connect() connects to. 1 Share this post Link to post