public static void main(String[] args) throws SocketException,
IOException {
FTPClient ftp = new FTPClient();
ftp.connect("ftp.petrobras.com.br");
ftp.login("usuario", "senha");
ftp.changeWorkingDirectory("meuDir");
String[] arq = ftp.listNames();
System.out.println("Listando arquivos: \n");
for (String f : arq) {
System.out.println(f);
}
}
}[/code]
Erro apresentado:
[color=darkred]java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - package org.apache.commons.net.ftp does not exist
at Swing.Ftp.([/color][color=blue]Ftp.java:5[/color][color=darkred])
Could not find the main class: Swing.Ftp. Program will exit.
Exception in thread “main” Java Result: 1[/color]
Qual biblioteca devo importar? É essa mesmo (org.apache.commons.net.ftp.FTPClient)?
public static void main(String[] args) throws SocketException,
IOException {
FTPClient ftp = new FTPClient();
ftp.connect("ftp://193.43.36.131/");
//ftp.login("temporario","");
//ftp.changeWorkingDirectory("meuDir");
String[] arq = ftp.listNames();
System.out.println("Listando arquivos: \n");
for (String f : arq) {
System.out.println(f);
}
}
}[/code]
Mas aparece este erro:
[color=darkred]Exception in thread “main” java.net.UnknownHostException: ftp://193.43.36.131/
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
at java.net.InetAddress.getAllByName(InetAddress.java:1084)
at java.net.InetAddress.getAllByName(InetAddress.java:1020)
at java.net.InetAddress.getByName(InetAddress.java:970)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:196)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:289)
at Swing.Ftp.main([/color][color=blue]Ftp.java:12[/color][color=darkred])
Java Result: 1[/color]