Reputation: 99
I want to show list of file which is available on ftp server i am working with some demo ftp server but it is not working it is showing some error , I have to get list of all file available on ftp server here is code
public class getFTPfileList {
public static void main(String[] args) {
FTPClient client = new FTPClient();
try {
client.connect("ftp.javacodegeeks.com");
client.login("username", "password");
FTPFile[] files = client.listFiles();
for (FTPFile ftpFile : files) {
if (ftpFile.getType() == FTPFile.FILE_TYPE) {
System.out.println("File: "
+ ftpFile.getName()
+ "size-> "
+ FileUtils.byteCountToDisplaySize(ftpFile
.getSize()));
}
}
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
The error message showing:
java.net.UnknownHostException: ftp.javacodegeeks.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:184)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:273)
at com.journaldev.servlet.getFTPfileList.main(getFTPfileList.java:21)
Upvotes: 0
Views: 505
Reputation: 4525
It seems that your FTP host is either not reachable or the host-name is incorrect and not resolved as a host-name.
See here : SocketClient#connect(String hostname)
Note : try it using IP-address of host server and ping it to check whether it is open or not.
Upvotes: 1