how can i delete a file from ftp server with a nifi processor?

The issues comes with how you define a flow being ‘finished’.

NiFi is designed to work on continuous streams rather than stop/start flows – hence why the Get/FetchFTP allow you to delete/move files after they have been processed – because it is expecting to continue running and be fed more files.

Rather than re-consuming the entire file in the case of a failure, you could write failed FlowFiles/Records somewhere (PutFile, PutFTP, PutHDFS, etc.).

That being said, to answer the direct question;

There is no direct processor to just delete from FTP.

As a workaround, you could add an extra GetFTP with Delete Original and auto-terminate the Success relationship – this would consume the file again but immediately drop the FlowFiles and delete the file. If they are big files, this might be a lot of unnecessary network traffic.

Alternatively, you could use an ExecuteStreamCommand to execute a script that can reach out and delete the file. You can pass the FTP host address, file path and file name as parameters to the script from the ESC processor.

Or, rather than GetFTP, you could use ListFTP and FetchFTP, and then use the Move File Completion Strategy to move processed files to an Archive directory. In the case of an error, you would be able to retreive files from the Archive directory. Then handle cleaning up the Archive however you want.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top