Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

How to send csv file instead of zip using SFTP Connector

SureshPatike
Regular Contributor
Regular Contributor

We have configured SFTP connector to transfer file from analytics generated to customer SFTP location.

We see SFTP connector sending zip formated file to SFTP location from Saviynt analytics location after job execution successfully.

But customer is expecting us to send file in csv formmated file in specific file name not the analytics generated random name contains <reportname>hkey***.zip.

We are looking for help what would be approach we can use with the available options in Saviynt to achieve this. 

Appreciated help.  

21 REPLIES 21

rushikeshvartak
All-Star
All-Star

You need to use custom jar code to extract zip file and send required file to client sftp. 

Refer https://forums.saviynt.com/t5/identity-governance/how-put-report-file-to-sftp-server/m-p/74807#M4750...


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Thank you for your quick response.

Am new to Saviynt and need your help how to configure custom jar to extract zip from analytics location. Let me know if you have any sample java file to connect analytics and extract zip, place it back with right file name. It would be great if you can help me on this. I have searched all over to forum posts and didn't get right direction on this. Thank you.

Use saviynt APIs

  1. To Run Report https://documenter.getpostman.com/view/23973797/2s9Ykhh4VH#f3737269-0c06-4273-8d38-d7622e655da8 
  2. Upload csv file in datafiles https://documenter.getpostman.com/view/23973797/2s9Ykhh4VH#d192104b-2fe3-4bc7-9b3a-e391cb9da057 

 

  • API 1 will run report and stored file in location specified in Report
  • Once report is generated extract zip using below sample code 
  • Upload files in databases using API2

 

Refer sample Java Code

Spoiler

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipExtractor {
public static void main(String[] args) {
String zipFilePath = "path/to/your/zipfile.zip";
String csvFileName = "example.csv";

try {
ZipFile zipFile = new ZipFile(zipFilePath);
ZipEntry entry = zipFile.getEntry(csvFileName);

if (entry != null) {
InputStream inputStream = zipFile.getInputStream(entry);
OutputStream outputStream = new FileOutputStream(new File(csvFileName));

byte[] buffer = new byte[1024];
int length;

while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}

outputStream.close();
inputStream.close();
zipFile.close();

System.out.println("CSV file extracted successfully.");
} else {
System.out.println("CSV file not found in the ZIP archive.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Thank you so much and it's really great info for me to start. I will try this and let you know how that goes.

Is the zipFilePath in sample code just need to be /Analytics/<reportname> or am I missing something here.

/saviynt_shared/reports/Archive/Analytics/ReportName.zip

ReportName remove spaces - You can download report from UI to check report naming convention


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Are Step#1 an Step#3 really need if analytics job scheduled to run and step#2 doing file rename? To upload file after extract and renamed from zip to csv (step#2), we will be using SFTP File Transfer Job through connector to SFTP location. 

We use trigger chain job to run all of these steps in order. Let me know if my understanding or approach is not correct.

You can follow triggerchain


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Thank you, i have done some changes to your java code to read zip file from the folder above and created jar with java version 11.0.18 (OpenJDK). 

Am getting below error after running external jar job with this jar class. Does this mean uploaded jar (compiled class) not supported with saviynt java version? Could you please let me know whats the saviynt support java version, so that i will create jar with that JDK version and upload jar again.

2024-04-04T23:26:00.12169025Z stdout F org.quartz.JobExecutionException: com/test/ZipExtractor has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [com.test.ZipExtractor]) [See nested exception: java.lang.UnsupportedClassVersionError: com/test/ZipExtractor has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [com.onetrust.modernhealth.ZipExtractor])]

Now, i have uploaded the jar file compiled on JDK1.8. Am not seeing above error now. Could you please let me know what do i need to pass Method name and arguments where my class has only 

public static void main(String[] args)

SureshPatike_0-1712276987059.png

2024-04-05T00:23:41.829641953Z stdout F 2024-04-05 00:23:41,829 [quartzScheduler_Worker-3] DEBUG jobs.ExternalJarJob  - START ExternalJarJob
2024-04-05T00:23:41.841099356Z stdout F 2024-04-05 00:23:41,841 [quartzScheduler_Worker-3] DEBUG jobs.ExternalJarJob  - Lets Invoke Class Namecom.test.ZipExtractor method 
2024-04-05T00:23:41.841141556Z stdout F 2024-04-05 00:23:41,841 [quartzScheduler_Worker-3] DEBUG jobs.ExternalJarJob  - arguments: 
2024-04-05T00:23:41.857504202Z stdout F 2024-04-05 00:23:41,841 [quartzScheduler_Worker-3] ERROR jobs.ExternalJarJob  - Error: 
2024-04-05T00:23:41.857543403Z stdout F groovy.lang.MissingMethodException: No signature of method: com.test.ZipExtractor.() is applicable for argument types: () values: []
2024-04-05T00:23:41.857549903Z stdout F Possible solutions: is(java.lang.Object), any(), wait(), find(), use([Ljava.lang.Object;), grep()
2024-04-05T00:23:41.857554903Z stdout F at ExternalJarJob.execute(ExternalJarJob.groovy:90)
2024-04-05T00:23:41.857559103Z stdout F at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
2024-04-05T00:23:41.857563403Z stdout F at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546)

method name - main


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Should i need to pass any value for arguments field on job configuration or just leave it blanl since its main method? 

if your jar needs it then share.

Share Jar for further help


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Here is jar attached. actually we dont need any inputs from arguments in logic to perform. i have added system.out.println statements but i dont see any logs in log viewer, also i have added logger class but that was also not helpful. This what i see when i dont pass arguments field.

2024-04-05T04:10:52.767471605Z stdout F 2024-04-05 04:10:52,767 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - START ExternalJarJob
2024-04-05T04:10:52.800555582Z stdout F 2024-04-05 04:10:52,800 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - Lets Invoke Class Namecom.onetrust.modernhealth.ZipExtractor method main
2024-04-05T04:10:52.805333722Z stdout F 2024-04-05 04:10:52,805 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - arguments: 
2024-04-05T04:10:52.821251555Z stdout F 2024-04-05 04:10:52,821 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - Writing job history to import logs.
2024-04-05T04:10:52.821282355Z stdout F 2024-04-05 04:10:52,821 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - Number of log entries to be written : 3
2024-04-05T04:10:52.848262181Z stdout F 2024-04-05 04:10:52,848 [quartzScheduler_Worker-2] DEBUG jobs.ExternalJarJob  - END ExternalJarJob

There are no arguments needed. If you need further code help you can work with TAM/SI Partner


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

am able to execute code through external jar job, but not sure we can read files from the location as you provided the path above.

/saviynt_shared/reports/Archive/Analytics/<reportname>.zip
or
/saviynt_shared/reports/Archive/Analytics/
Please confirm me whether we can really read files from the location /saviynt_shared/reports/Archive/Analytics/ through code executed through external jar job. 

You can


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Thank you @rushikeshvartak for all your help. i was able to read saviynt reports folder location and extract zip, rename to csv file succesfully. i was able to copy csv file to same location as well and make it available for SFTP connector.

one change: files can be read from folder location is: /saviynt_shared/reports/Analytics/<analyticsreportname>/ not /saviynt_shared/reports/Archive/Analytics/<analyticsreportname>/

Great You can share working jar for others benefits


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

Hi @SureshPatike Could you please share working jar and all steps to extract zip file? We have to send csv file to SFTP server.

SureshPatike
Regular Contributor
Regular Contributor

sending java file as attached in zip.

Please click the 'Accept As Solution' button on the reply (or replies) that best answered your original question.


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.