Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

What I want to do is to override onUploadStart method to have custom upload localization (temporary folder) and then override onUploadEnd method to copy succesfully uploaded file to it's original destination folder. Apache Mina FTP Server homepage says that "This notification method will be called to indicate that the file transfer is successful and the server has send the replies. In case of any error this method will not be called. This is called in STOR command." But... onUploadEnd method is called even if transfer was ended by interrupt. Take a look at this code:

public class TestFtplet extends DefaultFtplet{
@Override
public FtpletResult onUploadStart(FtpSession session, FtpRequest request) {
    System.out.println("Receiving upload request. Starting...." + request.getCommand());
    return FtpletResult.DEFAULT;
@Override
public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) {
    System.out.println("Ending uploading.... "+ request.getCommand() + request.getArgument() + request.getRequestLine());
    System.out.println(": " + session.getUserArgument() + session.toString());
    return FtpletResult.DEFAULT;

I have exactly this same output if upload was interrupted or not. Is there any way to catch ABOR request during transfer?

I wrote another code inside overrided method beforeComand (code below runs when request.getCommand() is STOR):

                        System.out.println("\n\n****** RECEIVED UPLOAD REQUEST *******\n\n");
                DataConnectionFactory dataConnectionFactory = session.getDataConnection();
                try {
                    System.out.println("Receiving file " + request.getArgument());
                    temporaryFile = File.createTempFile("FTP_", ".tmp");
                    OutputStream outputStream = new FileOutputStream(temporaryFile);
                    DataConnection dataConnection = dataConnectionFactory.openConnection();
                    session.write(new DefaultFtpReply(150, "Transfering data..."));
                    dataConnection.transferFromClient(session, outputStream);
                    System.out.println("Writing file to temporary destination " + temporaryFile.getAbsolutePath());
                    outputStream.flush();
                    outputStream.close();
                    Path source = Paths.get(temporaryFile.getAbsolutePath());
                    Path destination = Paths.get("C:\\apache-ftpserver-1.0.6\\res\\home\\"+request.getArgument());
                    if(request.getCommand().toUpperCase().equals("ABOR")) {
                        System.out.println("Upload interrupted!");
                        destination = Paths.get("C:\\apache-ftpserver-1.0.6\\res\\unfinished\\"+request.getArgument());
                        Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
                        System.out.println("Moved file to " + destination);
                    } else {
                        Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
                        System.out.println("Done! File moved to " + destination);

it's succesfully writing file to temporary folder, but if(request.getCommand().toUpperCase().equals("ABOR")) allways returns false, even if FTP Client interrupted uploading and sent ABOR. Is there any way to handle this?

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.