Here the way of Connecting the FTP client
private static final DateFormat dateFormat = DateFormat
.getDateTimeInstance();
public static void main(
String[] args) throws InstantiationException,
ClassNotFoundException, IllegalAccessException, FTPException,
ParseException, ConnectionException {
String ftpClientClassName = "com.myjavaworld.ftp.DefaultFTPClient";
String listParserClassName = "com.myjavaworld.ftp.DefaultListParser";
FTPClient client = (FTPClient) Class.forName(ftpClientClassName)
.newInstance();
ListParser parser = (ListParser) Class.forName(listParserClassName)
.newInstance();
client.setListParser(parser);
client.addFTPConnectionListener(new FTPConnectionListener() {
public void connectionOpened(FTPConnectionEvent evt) {
System.out.println(evt.getMessage());
}
public void connectionClosed(FTPConnectionEvent evt) {
System.out.println(evt.getMessage());
}
});
client.addControlConnectionListener(new ControlConnectionListener() {
public void commandSent(ControlConnectionEvent evt) {
System.out.println(evt.getMessage());
}
public void replyReceived(ControlConnectionEvent evt) {
System.out.println(evt.getMessage());
}
});
client.setPassive(true);
client.connect("hostname", 21);
client.login("username", "password");
RemoteFile workingDirectory = client.getWorkingDirectory();
list(client);
client.setWorkingDirectory(parser.createRemoteFile(workingDirectory,
".", true));
list(client);
client.disconnect();
}
private static void list(FTPClient client) throws FTPException,
ParseException, ConnectionException {
RemoteFile[] children = client.list();
for (int i = 0; i < children.length; ++i){
System.out.println("---------------------------owner-----------------"+children[i].getOwner()+"-----------------getfilename-----"+children[i].getName());
}
/*+ "\t"
+ ((children[i].isDirectory()) ? "<DIR>" : "<FILE>")
+ "\t"
+ children[i].getSize()
+ "\t"
+ dateFormat.format(new Date(children[i]
.getLastModified())) + "\t"
+ children[i].getName());*/
}
}
here the output of owner showing "Owner" in my case.
please give help on the same.
Thanks
Hanuman