• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I get Owner name of a file which is located in FTP server

 
hanuman karyampudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How do i get Owner name of a file which is located in FTP.
please give me any guidance.

Advance Thanks
Hanuman
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you connecting to the FTP server? I know the Apache Commons Net library provides a method to get the owner name.
 
hanuman karyampudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your question is actually: why doesn't jMethods Secure FTP return the owner.
It looks like Secure FTP works like the Apache library. It takes the text output from an FTP server and parses it into a Java object. Unfortunately, if the format of the FTP server's replies don't match a known format, the parser will fail.
I would log into the FTP server by hand and see if it provides the owner when listing files. If it doesn't, then you aren't getting it without reconfiguring the server. If the FTP server does provide the owner, you can either try the Apache library and see if it works better or manually configure a parser for the jMethods library.
 
hanuman karyampudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using Commons net API, I am not using Jmethods Secure FTP.
Please help me How to get owner of a file which is located in FTP server.

Advance Thanks
Hanuman
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hanuman karyampudi wrote:Hi I am using Commons net API


The code above contains classes in the package com.myjavaworld.ftp. There are no such classes in the Apache Commons Net library, so either you posted the wrong code or you think you are using a different API than you actually are.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!