0
Good evening guys, I’m trying to make a simple program that lists the files of an FTP directory, and error is occurring.
package br.com.java;
import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnect {
public static void main(String[] args) throws SocketException, IOException{
    // TODO code application logic here
    FTPClient ftp = new FTPClient();
    ftp.connect("ftp.endereco.com.br");
    ftp.login("usuario","senha");
    if(FTPReply.isPositiveCompletion(ftp.getReplyCode()) ){
        System.out.println("Conectado!!");
        ftp.enterLocalActiveMode();
    }
    ftp.changeWorkingDirectory("/pasta/subpasta");
    System.out.println(ftp.getReplyString());
    System.out.println("porta: " + ftp.getDefaultPort());
    try {
        String[] arq = ftp.listNames();
        System.out.println("Listando arquivos \n");
        for (String f : arq){
            System.out.println(f);
        }
        ftp.logout();
        ftp.disconnect();
    } catch (NullPointerException e) {
        System.out.println(e.getMessage());
    }catch (SocketException es){
        System.out.println(es.getMessage());
    }
}
 }
The output result is:
run: Conectado!! 250 CWD command successful porta: 21 Listando arquivos null CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)
Does anyone have any idea what might be going on?
When I try to do by CMD the information that appears is this:
ftp> ls 
500 PORT/EPRT (Active Mode/Extended Active Mode) is not supported. Use PASV/EPSV
 instead of this
425 Unable to build data connection: Invalid argument
ftp> pasv
Comando inválido.
ftp>– Fabio Aragão
Guys, I managed to resolve the issue by changing
ftp.enterLocalActiveMode();forftp.enterLocalPassiveMode();– Fabio Aragão