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?