'FTP connection error with Failed to retrieve directory listing

I am trying to connect to a FTP server hosted on azure VM using IIS I can connect but I keep getting the following error:

Error: Connection timed out after 20 seconds of inactivity

Error: Failed to retrieve directory listing



Solution 1:[1]

Could you disable the firewall and try FTP to a different server?

Do you have an NSG (Network Security Group) associated with your VM ?, If yes then you'll need to open port 21/990 to access your FTP Server Use Azure Powershell to setup the ports and check for the status. Azure now have an FTP VM in the marketplace that fully setups FileZilla FTP Server https://azuremarketplace.microsoft.com/en-gb/marketplace/apps/cloud-infrastructure-services.filezilla-ftp-server

Setup instructions: https://cloudinfrastructureservices.co.uk/install-filezilla-secure-ftp-server-on-azure-server-2016/ You need to add an additional port range, which the ftp server will choose from for each ftp connection.

While the Windows firewall is automatically configured with rules for the ports 21, 990 and 1024-65535, when IIS FTP server is installed, the rules are not enabled initially. To enable or change the rules, go to Control Panel > System and Security > Windows Firewall > Advanced Settings > Inbound Rules and locate three "FTP server" rules. If the rules are not enabled, click on Actions > Enable Rule.

https://winscp.net/eng/docs/guide_windows_ftps_server

Refer to the suggestion mentioned here: Cannot list directory on IIS FTP server on Azure, even after configuring Azure inbound rules and Windows firewall

Additional information: https://serverfault.com/questions/279286/how-to-resolve-ftp-error-failed-to-retrieve-directory-listing-for-administrato

If you are using passive mode the server opens a random unprivileged port above 1023. Therefore in order to work you would need to open up a range of ports in Azure. If you need this to work in passive mode your best bet is to use an FTP server where you can configure the passive mode port range, and then create the corresponding inbound port range rule in Azure (and in the OS). If you have any alternatives I wouldn't do it, since the fewer ports you expose the better.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SumanthMarigowda-MSFT