FTP connection is not listing files

2

I am not able to list the files in the folder via FTP (by Filezilla I can access list correctly):

FTPClient ftp = new FTPClient();

ftp.connect("ip_ftp");
ftp.login("usuario", "senha");
System.out.println("conectado: " + ftp.isConnected()); //verifica se conectou
ftp.enterLocalPassiveMode();

ftp.changeWorkingDirectory("diretorio"); //informa o diretorio que eu quero acessar

System.out.println("Status: " +ftp.getStatus()); //verifica se ainda esta conectado
System.out.println(ftp.printWorkingDirectory()); //informa o diretório que estou

String[] arq = ftp.listNames(); //lista o arquivos
System.out.println("Listando arquivos: \n");
for (String f : arq) { //imprimre os arquivos
    System.out.println(f);
}

But this is giving the following error:

Permission denied: recv failed

I'm using the following libraries:

import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
    
asked by anonymous 25.11.2015 / 14:50

2 answers

1

Probably some block on port 20, FTP uses port 21 to authenticate and port 20 to traffic data.

Your code is working in active mode , typically active-mode FTP is a connection problem when listing and downloading files, especially when behind providers or Firewalls.

If you use passive FTP (which is the same as Filezilla uses by default) it will probably work.

A more detailed link on how FTP works link

    
16.05.2016 / 21:53
0

As per the question in SOen this problem:

  

Permission denied: recv failed

This is due to the lack of an update (maybe in the latest versions of windows not happening) that causes problems in FTP connections in passive mode in IPV4, follow the link:

  

link

Hotfix Download Available:

  

link

Alternatively you can try instead of using passive mode :

ftp.enterLocalPassiveMode();

Switch to active mode :

ftp.enterLocalActiveMode();
    
24.08.2017 / 20:13