Issue at Hand
You are reporting that you cannot connect to your remote
ftp server. You receive the following error message:
I won't open a connection to x.x.x.x remote server ip (only to x.x.x.x my public ip)
Depending on if you are using a
php ftp or
vsftpd solution as your
ftp server solution, I may have found 2 possible solutions.
1. Possible VSFTP Configuration Fix
Potentially you need to only correct your
vsftp configuration. I have found this forum post by user nhtrader that could provide a possible solution. Please read over it in its entirety to make sure it applies to you.
First off, Is this an
ftp server located remotely or within your home/LAN? Verify that you can authenticate, or at least communicate to the server without using your
Second, verify that your router can support port forwarding and add the relevant ports you need to the router's port forwarding list. If you are using a VPS for the
ftp server, please reference their documentation regarding port forwarding and support methods for
ftp, authentication, remote management, etc.
The GRC, provides a decent tool to verify if your home network is blocking any ports or services you will require. This can be a good check to verify that your port forwarding works and is not blocked by your ISP. You will also need to create firewall rules on both your host and server to allow for connections via the ports you wish to use.
Third, edit your
vsftpd configuration file located at
Add the following entries to the file using
sudo nano /etc/vsftpd.conf:
ftpd_banner=[Whatever message of your choice]
The following entries can be up to you as what ports you want to use, these are just the ones user nhtrader used.
If you are using a dynamic IP address and do not have static use this entry:
If you are using a static IP address use this instead:
Save and close the configuration file and restart the
sudo systemctl restart vsftpd.service
Now you should be able to connect to your ftp server properly. Again, I suggest looking over the entirety of the forum post as it covers a lot of information and possible issues.
2. Possible PHP Fix
According user Martin Prikryl in this stack overflow post, you can solve that exact error message by moving
ftp_login in the
php module you are using on your server.
$conn_id = ftp_connect('x.x.x.x');
ftp_login($conn_id, 'user', 'pass');
He found this answer by consulting the php documentation. Please read over all the links to make sure this is an applicable fix for you.
First, verify that your
vsftpd or other
ftp server configuration is correct, that your firewall allows
ftp connections and that you can even connect to your host. Consult your VPS or router documentation for best practices in doing this.
I will be including a link to the
vsftpd manpage for reference as well. It has a link to a page explaining what each entry of the configuration file does.
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!