Thanks, I think I figured out how to do it. This kind of works, but I was
wondering if anyone knows a good format for the ftp LIST reply?
public FtpletResult beforeCommand(FtpSession session, FtpRequest
request) throws FtpException, IOException
{
if(request.getCommand().equals("LIST"))
{
try
{
session.write(new DefaultFtpReply(150,
"Getting data connection."));
DataConnection dataConnection =
session.getDataConnection().openConnection();
dataConnection.transferToClient(session,
"Insert LIST output here");
session.write(new DefaultFtpReply(226,
"Transfer Complete."));
session.getDataConnection().closeDataConnection();
return FtpletResult.SKIP;
}
catch(Exception ex)
{
session.write(new DefaultFtpReply(551, "Data
transfer failed."));
}
}
return null;
}
-----Original Message-----
From: Janardhanan, Ajith (AJANARDH) [mailto:[email protected]]
Sent: 17. mars 2010 14:55
To: [email protected]
Subject: RE: LIST from database
Kenneth,
I had done something similar(connecting to MQ, getting a bunch of queue info
and displaying to the user as a dir structure).But the ftpserver codebase I
used was 2+ years old. So really don't know if this will still hold good.
This is what I did:
- Modified the execute() method in LIST.java file by adding
ftpletContainer.onLIST()
- Override onLIST() on my ftplet to have
I did something line this in LIST.java:
public void execute(Connection connection,
FtpRequest request,
FtpSessionImpl session,
FtpReplyOutput out) throws IOException, FtpException
{
try {
// reset state variables
session.resetState();
FtpServerContext serverContext = connection.getServerContext();
Ftplet ftpletContainer = serverContext.getFtpletContainer();
FtpletEnum ftpletRet;
try{
ftpletRet = ftpletContainer.onLIST(session, request, out);
} catch(Exception e) {
LOG.debug("Ftplet container threw exception", e);
ftpletRet = FtpletEnum.RET_DISCONNECT;
}
if(ftpletRet == FtpletEnum.RET_SKIP) {
return;
}else
if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
serverContext.getConnectionManager().closeConnection(connection);
return;
}
}
Good Luck!
Ajith
-----Original Message-----
From: Kenneth Vanvik Hansen [mailto:[email protected]]
Sent: Wednesday, March 17, 2010 9:39 AM
To: [email protected]
Subject: LIST from database
Hi, i have written an ftplet that puts a file and file info in a database
table. Now I need to get LIST to list information from the database. I was
wondering if something like this has been done before?
Would save me some time if someone had any solutions/ideas.
Kenneth