cancel
Showing results for 
Search instead for 
Did you mean: 

How to retain only hundred files in FTP folder

Former Member
0 Kudos

Hi All,

I have requirement where I need to retain only hundred files in my receiver FTP folder based on the file name which has a date (for example - abc_yyyymmdd.txt). 

For example, lets say the receiver FTP folder has hundred files until yesterday and when I run the interface today, the least dated file must get deleted and the new file should be added to the folder so that the files in the folder will be hundred always.

Is this possible doing from PI point of view? Please suggest me a solution?

Thanks,

Nani

Accepted Solutions (0)

Answers (1)

Answers (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

Yes this is possible but i dont advice to do it in PI.

PI Solution:

Write a JAVA mapping and perfrom File look and count number of files and delete old file. this is possible using JAVA code.

or

You can try using Shell script.

Regards,

Raj

Former Member
0 Kudos

Hello Raj,

Thanks for the reply. In my scenario no ESR is used (no mapping). The think the only way is by using Shell script. But, I do not know shell script? Please guide me with the steps where to write the shell script code.

Thanks,

Nani

rajasekhar_reddy14
Active Contributor
0 Kudos

You can use adapter module also before callSAPAdapter module execute developed adapter module .

You need help from UNIX team to develop a script as per your required, the script has to count number of files and it should delete old file from FTP,and call script in sender channel.

Former Member
0 Kudos

I went thru some documentation in achiving ouput for this but I still didn't understand how to achieve this. Appreciate if somebody could help me build steps in achieving this.

Thanks,

Nani

Former Member
0 Kudos

Hi Nani,

Do you know what operating system the receiver FTP server is running on? I also think trying to achieve this through SAP PI is going to cause more problems than it will solve...You are essentially trying to manage archiving on the FTP server? If so, the archiving responsibility needs to be on that side.

If you were trying to manage this on the PI file system this would work fine. If your PI system runs on Unix you could issue a a few commands like :

- ls | head -100 (default listing sorted by filename) - OR -

- ls -lt | head -100 (listing by timestamp).

Then write the listing output to a file. Then use a Unix FOR loop to interate through the files in the directory and move all files out that do not appear in you top 100 listing.

To achieve this while in FTP mode, would result in poor design. In the script you could essentially end up doing a scenario like the following example...

- need to do 2 file listings (1 full listing & 1 top 100 listing), write the 2 outputs to files, then FTP those back to the PI server.

- Still in the script, do a FOR LOOP to loop through the full listing output file and do a GREP against the top 100 file. If it doesn't exist, FTP to receiver and issue a move or delete FTP command for that file.

You will iterate through this doing an FTP for each file that doesn't exist in the top 100 listing. This could equate to a lot of FTP calls - hence my poor design suggestion...

Regards, Trevor