Error when listing FTP file

0

Good night everyone, I'm trying to make a simple program that lists the files of an FTP directory, and an 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 an idea of what might be happening?

    
asked by anonymous 02.01.2018 / 21:31

1 answer

0

The problem does not look like Java, but the user's permission on the server, The user may not have access to list, check online at link | If you have access to the server and it is Linux, run the sudo chmod 777 / home command / user / folder_ftp
another detail is the configuration of the firewall port 20 (data).

    
03.01.2018 / 01:46