cancel
Showing results for 
Search instead for 
Did you mean: 

Zipping multiple files in target SFTP server through PI with dynamic file name

Former Member
0 Kudos

Hello Friends,

I have an requirement to zip multiple files in target SFTP server with dynamic file name inside the ZIP file.

I went through lot of postings in SDN but I have  got only one solution to achieve this functionality is through custom adapter module.

Could anybody please  provide me the solution to achieve this functionality other than custom adapter module.

I am looking for the script with OS commands to execute after post command option in SFTP receiver channel.

Thanks,
Satheesh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Satheesh,

  Below is an alternative approach to achieve your requirement. It's a two stage approach where you first need to save all the files in a temporary folder either on PI NFS or on the SFTP server.

Source System --> PI --> SFTP Server (Temporary Folder)

SFTP Server (Temporary Folder) --> PI (Java mapping) --> SFTP Server.

In the 2nd stage, you can pick all the files, zip them and place it on the SFTP server actual folder.

If you can elaborate more on the Dynamic Filename requirement, i can suggest propose a solution to achieve that.

You can go with this approach if you want to avoid scripts and custom adapter module.

Regards

Charan

Former Member
0 Kudos

HI Charan,

Thanks for the reply.

Currently I am placing the files in SFTP folder(Step1) with different file names. I am good with this logic. I need to ZIP them and place them into separate folder and delete the files.

Could you please provide me the stage 2 logic how to handle this scenario that will be great and its highly appreciated.

Thanks,

Satheesh

Former Member
0 Kudos

Hi Satheesh,

  What's your file naming convention of the files that you are placing in the SFTP server? This information is needed on how to process the files. There are 2 options to read the files and zip them.

  1. In the first stage, you can have a zero byte file to indicate that all the files to be zipped in the SFTP server are available to be read. In the 2nd stage, you can read this zero byte file as the main file and the other files as attachments. Zip all the attachments using a java mapping.
  2. You can read one of the files as the main file and remaining as attachments and use the same logic of using a java mapping to zip main file and all the attachments.

Hope this is clear. Let me know if you have any doubts.

Regards

Charan

former_member184720
Active Contributor
0 Kudos

>>>I am looking for the script with OS commands to execute after post command option in SFTP receiver channel.

This OS command gets executed on PI operating system.

So you need to write a java prog/perl script which will connect to SFTP server and zip the files.

You can find open libraries like zehon/jcraft to connect to SFTP server.

If you want to zip on PI server and then drop them on SFTP server (second flow), check below blog.

Former Member
0 Kudos

Hi Hareesh,

Thanks for the reply. Could you please let me know where I need to call this below OS command.

Do I need to call directly in execute post command option in PI SFTP receiver channel or do I need the create the BAT file to run this script and assign that path in execute post command option in PI SFTP receiver channel.

Please let me know.

Scenario I

To zip multiple files (with different name and extensions) and to create a single target zipped file. 

Approach

Use the following OS Commands: cmd /C "jar cvfM \\machine-name\foldername\zippedfolder\test.zip -C \\machine-name\foldername\files2zip ."

  1. Files which need to be zipped is kept in location : \\machine-name\foldername\files2zip
  2. Zipped file will be created in location \\machine-name\foldername\zippedfolder\zip and will have name test.zip.

Additionally the files that are zipped now needs to be deleted, which can be done through the command cmd /C "DEL /Q "\\machine-name\foldername\files2zip \*.*"" This approach can be used for zipping multiple files and keeping the zipped file in a particular directory. .

Thanks,
Satheesh

former_member184720
Active Contributor
0 Kudos

>>>Do I need to call directly in execute post command option in PI SFTP receiver channel or do I need the create the BAT file to run this script and assign that path in execute post command option in PI SFTP receiver channel.


It depends.


If you are placing the files on PI file system/mounted location then you can directly give the corresponding zip command under SFTP receiver channel.


If you are placing the files on SFTP adapter and then would like to zip them, as i said you need to write a java prog/perl script which does that for you. and then create a batch file to execute it.


Under OS Command, you should call that batch prog.



It's good to go with adapter module/ java mapping to this. Any prob in doing that?


Refer to Praveen's suggestion to maintain dynamic file-name and zipping.




Former Member
0 Kudos

Hi Hareesh,

I have tried this OS command to ZIP the files but its not working. I have placed this command in "Execute post command option in receiver communication channel".

Could you please correct me what I did wrong in the below command.

cmd /C "jar cvfM /TEST/TEST1/ZIP/TLogExport.zip -C /TEST/TEST1"

Thanks,
Satheesh