I managed to capture the file soon after the end of data transfer, the code
follows below. Niklas Gustavsson, is there any difference in doing on that
way i do, and file system implementation on your sugestion ?.
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
factory.setPort(21);
serverFactory.addListener("default", factory.createListener());
FtpServer server = serverFactory.createServer();
PropertiesUserManagerFactory userManagerFactory = new
PropertiesUserManagerFactory();
userManagerFactory.setFile(new File("/config/users.properties"));
serverFactory.setUserManager(userManagerFactory.createUserManager());
BaseUser user = new BaseUser();
user.setName("admin");
user.setPassword("admin");
user.setHomeDirectory("/ftpTest/");
ArrayList<Authority> authorities = new ArrayList<Authority>();
authorities.add(new WritePermission());
user.setAuthorities(authorities);
UserManager um = userManagerFactory.createUserManager();
um.save(user);
serverFactory.setUserManager(um);
Map<String, Ftplet> m = new HashMap<String, Ftplet>();
m.put("myFTPlet", new Ftplet() {
public void init(FtpletContext fc) throws FtpException {
}
public void destroy() {
}
public FtpletResult beforeCommand(FtpSession fs, FtpRequest fr)
throws FtpException, IOException {
return FtpletResult.DEFAULT;
}
public FtpletResult afterCommand(FtpSession fs, FtpRequest fr,
FtpReply fr1) throws FtpException, IOException {
String command = fr.getCommand();
String message = fr1.getMessage();
InetSocketAddress clientAddress = fs.getClientAddress();
System.out.println("Cliente: " + clientAddress + "
Comando: " + command + " mensagem: " + message);
if ("STOR".equals(command) && "Transfer
complete.".equals(message)){
FtpFile file =
fs.getFileSystemView().getFile("imagem0.svg");
System.out.println(file.getName());
}
return FtpletResult.DEFAULT;
}
public FtpletResult onConnect(FtpSession fs) throws
FtpException, IOException {
return FtpletResult.DEFAULT;
}
public FtpletResult onDisconnect(FtpSession fs) throws
FtpException, IOException {
return FtpletResult.DEFAULT;
}
});
serverFactory.setFtplets(m);
server.start();
--
------------------------------
Thomaz Luiz Santos
Linux User: #359356
http://thomaz.santos.googlepages.com/
On Thu, Feb 21, 2013 at 8:29 AM, Thomaz Luiz Santos <[email protected]
> wrote:
> Niklas Gustavsson
>
> thanks for answering my e-mail.
>
> and how could I do this, I have no idea how to start.
>
> --
> ------------------------------
> Thomaz Luiz Santos
> Linux User: #359356
> http://thomaz.santos.googlepages.com/
>
>
>
> On Wed, Feb 20, 2013 at 6:36 PM, Niklas Gustavsson
> <[email protected]>wrote:
>
>> On Wed, Feb 20, 2013 at 8:25 PM, Thomaz Luiz Santos
>> <[email protected]> wrote:
>> > I'm trying to use the apache ftpserver to receive files on my desktop
>> > application but I am not able to capture files from the client before
>> write
>> > on the filesystem, or finished data transfer, I wonder if have any
>> examples
>> > how to do this.
>>
>> The best way to do this would likely be to customize the file system
>> implementation used by FtpServer.
>>
>> /niklas
>>
>
>
>
>
>