I have an Apache web server running on this machine with Debian stable, this PHP program have to connect using FTP to a remote online server among other things.

Everything worked fine until I installed an FTP server (vsftpd version 3.0.3-8+b1), but I don't think this is the culprit.

Now I get this error

The exact error/s are:

I won't open a connection to x.x.x.x --->*remote server ip* (only to x.x.x.x ---->*my public ip*)

And can't even ls remote directories, getting this error instead:

Unable to list directory

I suspect this is because FTP runs in active mode "by default" now, but I am really not sure. Those errors seems something related with passive mode.

What do you think?

  • Debian version: Debian GNU/Linux 9
  • PHP version: 7.0.30-0+deb9u1

The PHP routines we are talking about are: ftp_login() and ftp_fput()

I think it's auto active mode because everytime I use ftp_pasv(, true) it does work fine. Didn't have to specify before.

  • Does the exact error message really have those ---> arrows? If not, please provide an exact error message and put your comments separately (for example, in the text). – roaima Aug 30 '18 at 7:38

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 ftp service.

  • 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 /etc/vsftpd.conf.

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 vsftpd service.

 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_pav after 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');

ftp_pasv($conn_id, true);

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!

  • 1
    this is a great! answer, I'll test it, I appreciate it. – Carondimonio Aug 29 '18 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.