Cannot list or download files from AWS EC2 FTP server from Heroku app

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Cannot list or download files from AWS EC2 FTP server from Heroku app on this date .

I have an AWS EC2 instance acting an FTP server as described here:
https://www.xadmin.net/how-to-setup-ftp-on-aws-ec2-instance/

The EC2 instance has a security group with custom TCP rules to allow connections from any IP.

enter image description here

Connections via FileZilla and other FTP clients are successful.

I have a Spring Boot app that connects to this EC2 FTP server and it works locally. However, when deployed to Heroku, attempts at listing files or getting specific files hangs without any error.
The Spring Boot app uses the full public URL to the EC2 instance as the FTP host (ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com).

How do I allow the Heroku app to access the EC2 FTP server?

Answer

Most probably the server is misconfigured and sends its internal IP address in the FTP PASV command response.

While FileZilla and many other FTP clients can workaround that, Heroku probably cannot.
Check FileZilla log file for:
Server sent passive reply with unroutable address in FileZilla.

If this is the case, you will need to fix your FTP server.