It's not very clear from your question : are the files you want to remove local to your application or remote, on the SFTP server ?
Below is an example of what I have in one my app, maybe that can help : incoming messages (with file name in payload) are first sent to remote SFTP server, and then are deleted locally
<integration:publish-subscribe-channel
id="sftpChannel" />
<!-- The processed file will be sftped to the server -->
<sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory" channel="sftpChannel" order="1"
charset="UTF-8" remote-file-separator="/" remote-directory="${sftp.remote.directory}"
remote-filename-generator-expression="payload.getName()" mode="REPLACE" />
<!-- sftped file will be removed from the staging folder -->
<integration:service-activator
input-channel="sftpChannel" output-channel="nullChannel" ref="sftpFileDeleter"
method="deleteAfterSftpingFile" order="2" />
with SftpFileDeleter being
public class SftpFileDeleter {
private static final Logger LOGGER = Logger
.getLogger(SftpFileDeleter.class);
@ServiceActivator
public void deleteAfterSftpingFile(Message<File> fileMessage) throws IOException{
Path fileToDeletePath = Paths.get(fileMessage.getPayload().getAbsolutePath());
Files.delete(fileToDeletePath);
LOGGER.info("[SENT]File Sent to Sftp Server and deleted:"+fileToDeletePath.getFileName());
}
}