cleaned up, formatted and made the project runnable after decompilation. Also added new configurations for UCB and NABARD servres

This commit is contained in:
2025-05-11 21:22:38 +05:30
commit a1965ce4a5
8 changed files with 1016 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
dependency-reduced-pom.xml
target/

69
pom.xml Normal file
View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.main</groupId>
<artifactId>RupayFileToCBS_PROD</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exec.mainClass>com.Main.Main</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>23.5.0.24.07</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- not using Maven Compiler Plugin as it is not necessay -->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>1.8</release>
</configuration>
</plugin> -->
<!-- Maven Shade plugin to build fat or uber jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.Main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,168 @@
package com.Main;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import com.fetchFile.FetchReportFile;
import com.sendFile.protocol.SSH.SSHProtocol;
public class Main {
public static void main(String[] args) {
String user = "";
String password = "";
String hostUcb = "";
String hostNabard = "";
String local_folder_path = "";
String local_archive_path = "";
String local_report_path = "";
String local_report_bkp_path = "";
String remote_file_path = "";
String remote_report_path = "";
String remote_report_pattern = "";
String transfer_protocol = "";
String remote_failed_path = "";
String local_failed_path = "";
String local_fileName = "";
String remote_fileName = "";
String dbUrl = "";
String dbUsr = "";
String dbPass = "";
String dbSchema = "";
int port = 22;
long sleep = 5L;
try {
InputStream input = Main.class.getClassLoader().getResourceAsStream("config.properties");
Properties prop = new Properties();
if (input == null) {
System.out.println("Sorry, unable to find config.properties");
return;
}
prop.load(input);
hostUcb = prop.getProperty("REMOTE_HOST_UCB");
hostNabard = prop.getProperty("REMOTE_HOST_NABARD");
user = prop.getProperty("REMOTE_USER");
password = prop.getProperty("REMOTE_PASS");
port = Integer.parseInt(prop.getProperty("REMOTE_PORT"));
sleep = Long.parseLong(prop.getProperty("SLEEP_TIME_MINS"));
local_folder_path = prop.getProperty("LOCAL_FOLDER_PATH");
local_archive_path = prop.getProperty("ARCHIVE_FOLDER_PATH");
local_report_path = prop.getProperty("LOCAL_REPORT_PATH");
local_report_bkp_path = prop.getProperty("LOCAL_REPORT_BKP_PATH");
remote_file_path = prop.getProperty("REMOTE_INPUT_FILE_PATH");
remote_report_path = prop.getProperty("REMOTE_OUTPUT_FILE_PATH");
transfer_protocol = prop.getProperty("TRANSFER_PROTOCOL");
remote_report_pattern = prop.getProperty("REMOTE_REPORT_PATTERN");
remote_failed_path = prop.getProperty("REMOTE_FAILURE_FILE_PATH");
local_failed_path = prop.getProperty("LOCAL_FAILED_PATH");
dbUrl = prop.getProperty("DB_URL");
dbUsr = prop.getProperty("DB_USER");
dbPass = prop.getProperty("DB_PASS");
dbSchema = prop.getProperty("DB_SCHEMA");
System.out.println("Config Properties read:");
System.out.println(
"REMOTE_HOST_UCB: "
+ hostUcb
+ "\nREMOTE_HOST_NABARD: "
+ hostNabard
+ "\nREMOTE_USER: "
+ user
+ "\nREMOTE_PASS: "
+ password
+ "\nREMOTE_PORT: "
+ port
+ "\nREMOTE_FILE_PATH: "
+ remote_file_path
+ "\nSLEEP_TIME: "
+ sleep
+ "\nLOCAL_FOLDER_PATH: "
+ local_folder_path
+ "\nTRANSFER_PROTOCOL: "
+ transfer_protocol);
} catch (Exception e) {
e.printStackTrace();
}
SSHProtocol send =
new SSHProtocol(
user,
password,
hostUcb,
hostNabard,
port,
local_fileName,
"",
remote_file_path,
remote_fileName,
local_archive_path,
local_folder_path,
dbUrl,
dbUsr,
dbPass,
dbSchema);
FetchReportFile fetch =
new FetchReportFile(
user,
password,
hostUcb,
hostNabard,
local_report_path,
local_report_bkp_path,
remote_report_path,
transfer_protocol,
port,
remote_report_pattern,
dbUrl,
dbUsr,
dbPass);
FetchReportFile fetchFailed =
new FetchReportFile(
user,
password,
hostUcb,
hostNabard,
local_failed_path,
"",
remote_failed_path,
transfer_protocol,
port,
remote_report_pattern,
dbUrl,
dbUsr,
dbPass);
try {
while (true) {
System.out.println("___________________________________________________");
try {
send.sendFileSSHUcb();
send.sendFileSSHNabard();
} catch (Exception e) {
e.printStackTrace();
}
try {
fetch.fetchFiles();
} catch (Exception e) {
e.printStackTrace();
}
try {
fetchFailed.fetchFiles();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Sleeping for:" + sleep + " Minutes");
System.out.println("___________________________________________________");
TimeUnit.MINUTES.sleep(sleep);
}
} catch (Exception e) {
System.out.println(e);
return;
}
}
}

View File

@@ -0,0 +1,96 @@
package com.fetchFile;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.sendFile.protocol.FTP.FTPProtocol;
import com.sendFile.protocol.SSH.SSHProtocol;
public class FetchReportFile {
String user;
String password;
String hostUcb;
String hostNabard;
String local_folder_path;
String local_folder_path_bkp;
String remote_file_path;
String transfer_protocol;
String remote_report_pattern;
String dbUrl;
String dbUsr;
String dbPass;
String dbSchema;
final DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
Calendar cal = Calendar.getInstance();
int port;
public FetchReportFile(
String user,
String password,
String hostUcb,
String hostNabard,
String local_folder_path,
String local_report_bkp_path,
String remote_file_path,
String transfer_protocol,
int port,
String remote_report_pattern,
String dbUrl,
String dbUsr,
String dbPass) {
this.user = user;
this.password = password;
this.hostUcb = hostUcb;
this.hostNabard = hostNabard;
this.local_folder_path = local_folder_path;
this.local_folder_path_bkp = local_report_bkp_path;
this.remote_file_path = remote_file_path;
this.transfer_protocol = transfer_protocol;
this.port = port;
this.remote_report_pattern = remote_report_pattern;
this.dbUrl = dbUrl;
this.dbUsr = dbUsr;
this.dbPass = dbPass;
}
public void fetchFiles() {
if (this.transfer_protocol.equals("SSH")) {
SSHProtocol ssh =
new SSHProtocol(
this.user,
this.password,
this.hostUcb,
this.hostNabard,
this.port,
this.local_folder_path,
this.local_folder_path_bkp,
this.remote_file_path,
"",
"",
"",
this.dbUrl,
this.dbUsr,
this.dbPass,
this.dbSchema);
ssh.fetchFileSSHUcb(this.remote_report_pattern);
ssh.fetchFileSSHNabard(this.remote_report_pattern);
} else if (this.transfer_protocol.equals("FTP")) {
FTPProtocol ftp =
new FTPProtocol(
this.user,
this.password,
this.hostUcb,
this.port,
this.local_folder_path,
this.remote_file_path,
"",
"");
ftp.fetchFileFTP(this.remote_report_pattern);
} else {
System.out.println("Invalid TRANSFER_PROTOCOL. Must be one of FTP or SSH");
}
}
}

View File

@@ -0,0 +1,17 @@
package com.moveFile;
import java.io.File;
public class Movefile {
public void movefile(File inpFile, String archivePath) {
try {
if (inpFile.renameTo(new File(archivePath + inpFile.getName()))) {
System.out.println("File is moved successful!");
} else {
System.out.println("File is failed to move!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,144 @@
package com.sendFile.protocol.FTP;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import com.moveFile.Movefile;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class FTPProtocol {
String user;
String password;
String host;
int port;
String local_fileName;
String remote_filePath;
String remote_fileName;
String archive_path;
public FTPProtocol(
String user,
String password,
String host,
int port,
String local_fileName,
String remote_filePath,
String remote_fileName,
String archive_path) {
this.user = user;
this.password = password;
this.host = host;
this.port = port;
this.local_fileName = local_fileName;
this.remote_filePath = remote_filePath;
this.remote_fileName = remote_fileName;
this.archive_path = archive_path;
}
public void sendFileFTP() {
System.out.println("Going to SEND files from remote Server via FTP");
FTPClient ftpClient = new FTPClient();
try {
System.out.println(
"Creating SSH Session: user@host:port |--->"
+ this.user
+ "@"
+ this.host
+ ":"
+ this.port);
ftpClient.connect(this.host, this.port);
ftpClient.login(this.user, this.password);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(2);
File firstLocalFile = new File(this.local_fileName);
String[] fileTokens = this.remote_fileName.split("-");
System.out.println(
"Going to create brancheise folder:" + fileTokens[0] + " at " + this.remote_filePath);
ftpClient.changeWorkingDirectory(this.remote_filePath);
try {
ftpClient.makeDirectory(fileTokens[0]);
} catch (Exception ex) {
System.out.println("Folder not created: " + ex.getMessage());
}
ftpClient.changeWorkingDirectory(fileTokens[0]);
InputStream inputStream = new FileInputStream(firstLocalFile);
System.out.println("Start uploading file");
boolean done = ftpClient.storeFile(fileTokens[1], inputStream);
inputStream.close();
if (done) {
System.out.println("The file is uploaded successfully.");
Movefile mv = new Movefile();
mv.movefile(firstLocalFile, this.archive_path);
}
} catch (Exception ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public void fetchFileFTP(String remote_report_pattern) {
System.out.println("Going to FETCH files from remote Server via FTP");
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(this.host, this.port);
ftpClient.login(this.user, this.password);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(2);
ftpClient.changeWorkingDirectory(this.remote_fileName);
ftpClient.makeDirectory("archive");
System.out.println("Current directory is " + ftpClient.printWorkingDirectory());
FTPFile[] ftpFiles = ftpClient.listFiles();
if (ftpFiles != null && ftpFiles.length > 0) {
for (FTPFile file : ftpFiles) {
if (file.isFile()) {
System.out.println("File is " + file.getName());
OutputStream output = new FileOutputStream(this.local_fileName + file.getName());
ftpClient.retrieveFile(file.getName(), output);
output.close();
ftpClient.rename(file.getName(), "archive/" + file.getName());
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,492 @@
package com.sendFile.protocol.SSH;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Properties;
import java.util.Vector;
import com.moveFile.Movefile;
public class SSHProtocol {
String user;
String password;
String hostUcb;
String hostNabard;
int port;
String local_fileName;
String local_folder_path_bkp;
String remote_filePath;
String remote_fileName;
String archive_path;
String local_folder_path;
String dbUrl;
String dbUsr;
String dbPass;
String dbSchema;
public SSHProtocol(
String user,
String password,
String hostUcb,
String hostNabard,
int port,
String local_fileName,
String local_folder_path_bkp,
String remote_filePath,
String remote_fileName,
String archive_path,
String local_folder_path,
String dbUrl,
String dbUsr,
String dbPass,
String dbSchema) {
this.user = user;
this.password = password;
this.hostUcb = hostUcb;
this.hostNabard = hostNabard;
this.port = port;
this.local_fileName = local_fileName;
this.local_folder_path_bkp = local_folder_path_bkp;
this.remote_filePath = remote_filePath;
this.remote_fileName = remote_fileName;
this.archive_path = archive_path;
this.local_folder_path = local_folder_path;
this.dbUrl = dbUrl;
this.dbUsr = dbUsr;
this.dbPass = dbPass;
this.dbSchema = dbSchema;
}
public void sendFileSSHUcb() throws SQLException {
ChannelSftp sftpChannel = null;
Connection connection = null;
Session session = null;
JSch jsch = new JSch();
String DBfilename = null;
String bankCode = null;
String DBfileType = null;
String DBfileId = null;
String DCCBCode = null;
String procDate = null;
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
Calendar cal = Calendar.getInstance();
String dateToday = sdf.format(cal.getTime());
ResultSet rs = null;
PreparedStatement ps = null;
ResultSet rs2 = null;
Statement statement = null;
Statement statement2 = null;
try {
System.out.println("Going to SEND files from remote Server via SSH");
System.out.println(
"Creating SSH Session: user@host:port |--->"
+ this.user
+ "@"
+ this.hostUcb
+ ":"
+ this.port);
session = jsch.getSession(this.user, this.hostUcb, this.port);
session.setPassword(this.password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(this.dbUrl, this.dbUsr, this.dbPass);
connection.setAutoCommit(false);
if (connection != null) {
System.out.println("DB Connected..");
}
ps =
connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ dateToday
+ "' and k.remarks = 'FILE GENERATED' AND k.bnk_code NOT IN ('0005', '0021')");
rs = ps.executeQuery();
while (rs.next()) {
int errCount = 0;
bankCode = rs.getString(1);
DBfilename = rs.getString(2);
DBfileType = rs.getString(3);
DBfileId = rs.getString(4);
DCCBCode = rs.getString(5);
procDate = rs.getString(6);
connection.commit();
System.out.println("Creating SFTP Channel.");
sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");
System.out.println(
"SFTP -- Local File Name: "
+ DBfilename
+ " Remote File Name: "
+ this.remote_fileName);
System.out.println(
"Going to create brancheise folder:" + bankCode + " at " + this.remote_filePath);
sftpChannel.cd(this.remote_filePath);
try {
sftpChannel.mkdir(bankCode);
} catch (Exception ex) {
System.out.println("Folder not created: " + ex.getMessage());
}
try {
sftpChannel.cd(bankCode);
sftpChannel.put(this.local_folder_path + DBfilename, DBfilename);
System.out.println("File copied to remote server Successfully, archiving file");
Movefile mv = new Movefile();
mv.movefile(new File(this.local_folder_path + DBfilename), this.archive_path);
System.out.println("File archived to: " + this.archive_path);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error pushing file:" + DBfilename);
errCount++;
}
if (errCount == 0) {
statement2 = connection.createStatement();
rs2 =
statement2.executeQuery(
"update "
+ this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
+ " SENT',FILE_SFTP_SND_TIME= to_date(to_char(SYSTIMESTAMP,"
+ " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS') where file_name='"
+ DBfilename
+ "' and BNK_CODE='"
+ bankCode
+ "' and file_id='"
+ DBfileId
+ "' and DCCB_CODE='"
+ DCCBCode
+ "' and PROC_DT='"
+ procDate
+ "' ");
connection.commit();
rs2.close();
System.out.println("File successfully pushed:" + DBfilename);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
sftpChannel.disconnect();
session.disconnect();
System.out.println("Disconnect SFTP Channel");
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public void sendFileSSHNabard() throws SQLException {
ChannelSftp sftpChannel = null;
Connection connection = null;
Session session = null;
JSch jsch = new JSch();
String DBfilename = null;
String bankCode = null;
String DBfileType = null;
String DBfileId = null;
String DCCBCode = null;
String procDate = null;
DateFormat sdf = new SimpleDateFormat("ddMMyyyy");
Calendar cal = Calendar.getInstance();
String dateToday = sdf.format(cal.getTime());
ResultSet rs = null;
PreparedStatement ps = null;
ResultSet rs2 = null;
Statement statement = null;
Statement statement2 = null;
try {
System.out.println("Going to SEND files from remote Server via SSH");
System.out.println(
"Creating SSH Session: user@host:port |--->"
+ this.user
+ "@"
+ this.hostNabard
+ ":"
+ this.port);
session = jsch.getSession(this.user, this.hostNabard, this.port);
session.setPassword(this.password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(this.dbUrl, this.dbUsr, this.dbPass);
connection.setAutoCommit(false);
if (connection != null) {
System.out.println("DB Connected..");
}
ps =
connection.prepareStatement(
"select k.bnk_code,k.file_name,k.file_type,k.file_id,k.dccb_code,k.proc_dt from "
+ this.dbSchema
+ ".kcc_sftp_log k where k.proc_stat = 'Y' and k.proc_dt = '"
+ dateToday
+ "' and k.remarks = 'FILE GENERATED' AND k.bnk_code IN ('0005', '0021')");
rs = ps.executeQuery();
while (rs.next()) {
int errCount = 0;
bankCode = rs.getString(1);
DBfilename = rs.getString(2);
DBfileType = rs.getString(3);
DBfileId = rs.getString(4);
DCCBCode = rs.getString(5);
procDate = rs.getString(6);
connection.commit();
System.out.println("Creating SFTP Channel.");
sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");
System.out.println(
"SFTP -- Local File Name: "
+ DBfilename
+ " Remote File Name: "
+ this.remote_fileName);
System.out.println(
"Going to create brancheise folder:" + bankCode + " at " + this.remote_filePath);
sftpChannel.cd(this.remote_filePath);
try {
sftpChannel.mkdir(bankCode);
} catch (Exception ex) {
System.out.println("Folder not created: " + ex.getMessage());
}
try {
sftpChannel.cd(bankCode);
sftpChannel.put(this.local_folder_path + DBfilename, DBfilename);
System.out.println("File copied to remote server Successfully, archiving file");
Movefile mv = new Movefile();
mv.movefile(new File(this.local_folder_path + DBfilename), this.archive_path);
System.out.println("File archived to: " + this.archive_path);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error pushing file:" + DBfilename);
errCount++;
}
if (errCount == 0) {
statement2 = connection.createStatement();
rs2 =
statement2.executeQuery(
"update "
+ this.dbSchema
+ ".KCC_SFTP_LOG set proc_stat='S',sftp_remarks='FILE"
+ " SENT',FILE_SFTP_SND_TIME= to_date(to_char(SYSTIMESTAMP,"
+ " 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS') where file_name='"
+ DBfilename
+ "' and BNK_CODE='"
+ bankCode
+ "' and file_id='"
+ DBfileId
+ "' and DCCB_CODE='"
+ DCCBCode
+ "' and PROC_DT='"
+ procDate
+ "' ");
connection.commit();
rs2.close();
System.out.println("File successfully pushed:" + DBfilename);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
sftpChannel.disconnect();
session.disconnect();
System.out.println("Disconnect SFTP Channel");
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public void fetchFileSSHUcb(String remote_report_pattern) {
try {
System.out.println("Going to FETCH files from remote Server");
JSch jsch = new JSch();
System.out.println(
"Creating SSH Session: user@host:port |--->"
+ this.user
+ "@"
+ this.hostUcb
+ ":"
+ this.port);
Session session = jsch.getSession(this.user, this.hostNabard, this.port);
session.setPassword(this.password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
System.out.println("Creating SFTP Channel.");
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");
sftpChannel.cd(this.remote_filePath);
System.out.println(sftpChannel.pwd());
String rootPath = sftpChannel.pwd();
Vector<ChannelSftp.LsEntry> list = sftpChannel.ls(sftpChannel.pwd());
for (ChannelSftp.LsEntry entry : list) {
System.out.println(
"Current File/Folder: " + entry.getFilename() + " isDir " + entry.getAttrs().isDir());
if (entry.getAttrs().isDir()) {
if (entry.getFilename().equals(".") || entry.getFilename().equals("..")) {
System.out.println("Skipping . and ..");
continue;
}
System.out.println("Found folder: " + entry.getFilename());
System.out.println("cd: " + rootPath + "/" + entry.getFilename());
sftpChannel.cd(rootPath + "/" + entry.getFilename());
System.out.println(sftpChannel.pwd());
Vector<ChannelSftp.LsEntry> subDirFileList = sftpChannel.ls(remote_report_pattern);
for (ChannelSftp.LsEntry subDirFiles : subDirFileList) {
if (!(new File(this.local_folder_path_bkp + "/" + subDirFiles.getFilename()))
.exists()) {
sftpChannel.get(
subDirFiles.getFilename(), this.local_fileName + subDirFiles.getFilename());
System.out.println(
"File: " + subDirFiles.getFilename() + " copied to :" + this.local_fileName);
continue;
}
System.out.println(
"File: " + subDirFiles.getFilename() + " already present in local path");
}
}
}
sftpChannel.disconnect();
session.disconnect();
System.out.println("Disconnect SFTP Channel");
} catch (Exception e) {
e.printStackTrace();
}
}
public void fetchFileSSHNabard(String remote_report_pattern) {
try {
System.out.println("Going to FETCH files from remote Server");
JSch jsch = new JSch();
System.out.println(
"Creating SSH Session: user@host:port |--->"
+ this.user
+ "@"
+ this.hostNabard
+ ":"
+ this.port);
Session session = jsch.getSession(this.user, this.hostNabard, this.port);
session.setPassword(this.password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
System.out.println("Creating SFTP Channel.");
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");
sftpChannel.cd(this.remote_filePath);
System.out.println(sftpChannel.pwd());
String rootPath = sftpChannel.pwd();
Vector<ChannelSftp.LsEntry> list = sftpChannel.ls(sftpChannel.pwd());
for (ChannelSftp.LsEntry entry : list) {
System.out.println(
"Current File/Folder: " + entry.getFilename() + " isDir " + entry.getAttrs().isDir());
if (entry.getAttrs().isDir()) {
if (entry.getFilename().equals(".") || entry.getFilename().equals("..")) {
System.out.println("Skipping . and ..");
continue;
}
System.out.println("Found folder: " + entry.getFilename());
System.out.println("cd: " + rootPath + "/" + entry.getFilename());
sftpChannel.cd(rootPath + "/" + entry.getFilename());
System.out.println(sftpChannel.pwd());
Vector<ChannelSftp.LsEntry> subDirFileList = sftpChannel.ls(remote_report_pattern);
for (ChannelSftp.LsEntry subDirFiles : subDirFileList) {
if (!(new File(this.local_folder_path_bkp + "/" + subDirFiles.getFilename()))
.exists()) {
sftpChannel.get(
subDirFiles.getFilename(), this.local_fileName + subDirFiles.getFilename());
System.out.println(
"File: " + subDirFiles.getFilename() + " copied to :" + this.local_fileName);
continue;
}
System.out.println(
"File: " + subDirFiles.getFilename() + " already present in local path");
}
}
}
sftpChannel.disconnect();
session.disconnect();
System.out.println("Disconnect SFTP Channel");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,28 @@
# REMOTE SFTP SERVER CREDENTIALS
REMOTE_HOST_UCB=142.79.249.123
REMOTE_HOST_NABARD=142.79.249.234
REMOTE_USER=ipkssftp
REMOTE_PASS=Wnb10U11BE7N26
REMOTE_PORT=4650
# LOCAL SAL FILE PATHS
LOCAL_FOLDER_PATH=/home/ec2-user/RUPAYKCCFILES/
ARCHIVE_FOLDER_PATH=/home/ec2-user/RUPAYKCCFILES/archive/
LOCAL_REPORT_PATH=/home/ec2-user/RUPAYKCCFILES/reportFiles/
LOCAL_REPORT_BKP_PATH=/home/ec2-user/RUPAYKCCFILES/reportFiles_bkp/
LOCAL_FAILED_PATH=/home/ec2-user/RUPAYKCCFILES/failedFiles/
# REMOTE FILE PATHS
REMOTE_REPORT_PATTERN=SAL_*
REMOTE_INPUT_FILE_PATH=IPKS_FILES/FROMIPKS/
REMOTE_OUTPUT_FILE_PATH=IPKS_FILES/TOIPKS
REMOTE_FAILURE_FILE_PATH=IPKS_FILES/FAILURE
# IPKS DATABASE CREDENTIALS
DB_URL=jdbc:oracle:thin:@ipksprod3.c7q7defafeea.ap-south-1.rds.amazonaws.com:1521:IPKS
DB_USER=pacs_db
DB_PASS=pacs_db
DB_SCHEMA=pacs_db
# APPLICATION CONFIGURATION
TRANSFER_PROTOCOL=SSH
SLEEP_TIME_MINS=10