FTP connection is not listing files

Asked

Viewed 1,128 times

2

I am not able to list the folder files via FTP (through 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 you’re making the following mistake:

Permission denied: recv failed

I am using the following libraries:

import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;

2 answers

1

Likely to be some lock on port 20, FTP uses port 21 to authenticate and port 20 to traffic data.

Your code is working on active mode, Usually Ftps in active mode occurs connection problem when listing and downloading files, especially when they are behind providers or Firewalls.

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

A more detailed link about how FTP works http://slacksite.com/other/ftp.html

0

As question no Soen this problem:

Permission denied: recv failed

occurs due to lack of an update (maybe in newer versions of windows does not occur) that causes problems in FTP connections on passive mode in IPV4, follow the link:

https://support.microsoft.com/en-us/help/2754804/ftp-client-does-not-establish-a-passive-mode-ftp-connection-to-an-ipv4

Download from Hotfix:

https://support.microsoft.com/hotfix/kbhotfix.aspx?kbnum=2754804&kbln=en-US

Alternatively you can try instead of using the Passive mode:

ftp.enterLocalPassiveMode();

Exchange for active mode:

ftp.enterLocalActiveMode();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.