Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how ot change file name moving another location using FetchSFTP

avatar
Contributor

Hi sir,

I am using ListSFTP 2.0.0-M1+FetchSFTP  processor  and move file another location. I have two issues

1. Every time it make a folder and inside the folder keep the file. Here is image:

enam_1-1711873146987.jpeg

 

2. I need to move file using filename like filename+uniqueid.xml

If my file name is test.xml , I will rename file name like test++uniqueid.xml.

I have used  below path for move destination directiory

/myfolder/${filename}

Here is the image of FetchSFTP :

enam_0-1711872953352.jpeg

What is wrong of my configuration?

Please help me..

 

 

 

5 REPLIES 5

avatar
Expert Contributor

Hi @enam,

1. Please set the Create Directory to false to avoid the folder creation.

saquibsk_0-1712227893690.png

2. you can change the filename using UpdateAttribute processor by following below steps:

   2.1:  let say your file name is "97435cb8-b8b1-4b4d-b60b-f6aa98a15ba9" and UUID is "97435cb8-b8b1-4b4d-b60b-f6aa98a15ba9" 

saquibsk_1-1712228147812.png

 

  2.2. Now drag the UpdateAttribute name  and writedown the below Expression Lang

saquibsk_2-1712228356541.png

updated file name

saquibsk_3-1712228411185.png

OR

saquibsk_4-1712228533405.png

 

Output:

saquibsk_5-1712228631489.png

 

  "Accept as Solution" if its work for you.

Shakib M.

avatar
Expert Contributor

Hi @enam ,

Did above solution help you?

Shakib M.

avatar
Contributor

Hi Sorry for late reply.

It move the file to my destination folder. But it create new folder destination folder..I want to stop create folder & move the file to my destination folder with new unique id and the file name. Here is the configuration: 

enam_1-1719484353358.png

In back file it  create new folder :

enam_2-1719484618551.png

But if I want to create directory false , it would not move the file to the directory. I also try add move destination directory like /home/account-to-account/${now:format('yyyMMddHHmmss')}_${filename} which also not working

 

 

avatar
Super Mentor

@enam 

The FetchSFTP processor only supports specifying a target directory path in which the source file on the SFTP server will be moved.  It does not support the renaming of the source file during that move. When you configure the filename in the "move destination directory" it creates that filename as a directory in which it puts the source file using the value from the FlowFiles "filename" attribute.

Your option is to set "completion strategy to "Delete File" and then route the "success" relationship via two separate outbound connections.  One connection will continue down your existing dataflow path.  The second connection will feed an UpdateAttribute processor (used to change filename) and then a putSFTP processor to write it back the SFTP server in the new directory.

MattWho_2-1719868618129.png

The NiFi FlowFile routed to "success" relationship in connection 1 will retain original filename.
The NiFi FlowFile routed to "success" relationship in connection 2 will have its original filename modified by the UpdateAttribute processor as follows before being written back to SFTP server in new folder via the putSFTP processor.

Update Attribute configuration (click "plus" icon to add new dynamic property):

MattWho_1-1719868535096.png

Property = filename
Value = ${filename:substringBeforeLast('.')}-${UUID}.${filename:substringAfterLast('.')}

You can then auto-terminate the success relationship of the putSFTP processor.  terminating FlowFile down path of connection 2 will have no impact on FlowFile routed to connection 1.  Make sure that you set the target path in the putSFTP processor (path does not include filename).

Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.

Thank you,
Matt

avatar
Super Mentor

@enam Have a slight mistake in my NiFi Expression Language (NEL) statement in my above post.

Should be as follows instead:

Property = filename
Value = ${filename:substringBeforeLast('.')}-${UUID()}.${filename:substringAfterLast('.')}

Thanks,

Matt