Loading

How to prevent duplicate filenames and get a unique filename when using the SFTP transport

Udgivelsesdato: Jul 16, 2025
Opgave

GOAL

When processing files retrieved via an SFTP transport, and using the tempDir attributes to move the file during processing, if two files with the same name are being processed at the same time then you may see an exception as the files try to overwrite each other;
 
Move myTestFile.txt to /C:/sftptest/InProgress/myTestFile.txt 
DEBUG 2018-02-13 15:41:34,918 [[sftp-demo].SFTP.receiver.01] org.mule.transport.sftp.SftpClient: Will try to rename /C:/sftptest/myTestFile.txt to /C:/sftptest/InProgress/myTestFile.txt 
ERROR 2018-02-13 15:41:34,919 [[sftp-demo].SFTP.receiver.01] org.mule.transport.sftp.SftpMessageReceiver: Error in poll 
java.io.IOException: Failure 
at org.mule.transport.sftp.SftpClient.rename(SftpClient.java:330) ~[mule-transport-sftp-3.8.6.jar:3.8.6] 
at org.mule.transport.sftp.SftpReceiverRequesterUtil.retrieveFile(SftpReceiverRequesterUtil.java:201)
Trin

Configure the transport to use the useTempFileTimestampSuffix. This will guarantee a unique file name based on the time that the file was moved to the temporary directory. If you need to access the unique file name during later processing, then this can be retrieved via the #[payload.fileName] MEL expression, whereas the original filename can still be retrieved via the #[message.inboundProperties.originalFilename] expression.

Please see the below documentation page for further details of the SFTP Transport;
https://docs.mulesoft.com/sftp-connector/latest/sftp-documentation

Vidensartikelnummer

001114593

 
Indlæser
Salesforce Help | Article