code formatting and migration of some more banks 0016, 0018, 0001, 0004, 0007
This commit is contained in:
57
.classpath
Normal file
57
.classpath
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="ignore_optional_problems" value="true"/>
|
||||||
|
<attribute name="m2e-apt" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="ignore_optional_problems" value="true"/>
|
||||||
|
<attribute name="m2e-apt" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
34
.project
Normal file
34
.project
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SSHFileToCbs_PROD</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1754758620396</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
5
.settings/org.eclipse.core.resources.prefs
Normal file
5
.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
2
.settings/org.eclipse.jdt.apt.core.prefs
Normal file
2
.settings/org.eclipse.jdt.apt.core.prefs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.apt.aptEnabled=false
|
9
.settings/org.eclipse.jdt.core.prefs
Normal file
9
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.8
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
@@ -5,84 +5,83 @@ import com.sendFile.protocol.FTP.FTPProtocol;
|
|||||||
import com.sendFile.protocol.SSH.SSHProtocol;
|
import com.sendFile.protocol.SSH.SSHProtocol;
|
||||||
|
|
||||||
public class SendLocalfile {
|
public class SendLocalfile {
|
||||||
String user;
|
String user;
|
||||||
String password;
|
String password;
|
||||||
String hostUcb;
|
String hostUcb;
|
||||||
String hostNabard;
|
String hostNabard;
|
||||||
String local_folder_path;
|
String local_folder_path;
|
||||||
String archive_path;
|
String archive_path;
|
||||||
String remote_file_path;
|
String remote_file_path;
|
||||||
String transfer_protocol;
|
String transfer_protocol;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
public SendLocalfile(
|
public SendLocalfile(
|
||||||
String user,
|
String user,
|
||||||
String password,
|
String password,
|
||||||
String hostUcb,
|
String hostUcb,
|
||||||
String hostNabard,
|
String hostNabard,
|
||||||
String local_folder_path,
|
String local_folder_path,
|
||||||
String remote_file_path,
|
String remote_file_path,
|
||||||
String transfer_protocol,
|
String transfer_protocol,
|
||||||
int port,
|
int port,
|
||||||
String archivePath) {
|
String archivePath) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.hostUcb = hostUcb;
|
this.hostUcb = hostUcb;
|
||||||
this.hostNabard = hostNabard;
|
this.hostNabard = hostNabard;
|
||||||
this.local_folder_path = local_folder_path;
|
this.local_folder_path = local_folder_path;
|
||||||
this.remote_file_path = remote_file_path;
|
this.remote_file_path = remote_file_path;
|
||||||
this.transfer_protocol = transfer_protocol;
|
this.transfer_protocol = transfer_protocol;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.archive_path = archivePath;
|
this.archive_path = archivePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendFiles() {
|
public void sendFiles() {
|
||||||
File folder = new File(this.local_folder_path);
|
File folder = new File(this.local_folder_path);
|
||||||
File[] listOfFiles = folder.listFiles();
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
|
||||||
for (File file : listOfFiles) {
|
for (File file : listOfFiles) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
System.out.println("Going to send file: " + file.getAbsolutePath());
|
System.out.println("Going to send file: " + file.getAbsolutePath());
|
||||||
String bankCode = file.getName().split("-")[0];
|
String bankCode = file.getName().split("-")[0];
|
||||||
String bankHost = "";
|
String bankHost = "";
|
||||||
if(bankCode.equals("0005") || bankCode.equals("0021")) {
|
if (bankCode.equals("0005") || bankCode.equals("0021") || bankCode.equals("0016")
|
||||||
bankHost = hostNabard;
|
|| bankCode.equals("0018") || bankCode.equals("0001") || bankCode.equals("0004")
|
||||||
} else {
|
|| bankCode.equals("0007")) {
|
||||||
bankHost = hostUcb;
|
bankHost = hostNabard;
|
||||||
}
|
} else {
|
||||||
|
bankHost = hostUcb;
|
||||||
|
}
|
||||||
if (this.transfer_protocol.equals("SSH")) {
|
|
||||||
|
if (this.transfer_protocol.equals("SSH")) {
|
||||||
SSHProtocol ssh =
|
|
||||||
new SSHProtocol(
|
SSHProtocol ssh = new SSHProtocol(
|
||||||
this.user,
|
this.user,
|
||||||
this.password,
|
this.password,
|
||||||
bankHost,
|
bankHost,
|
||||||
this.port,
|
this.port,
|
||||||
file.getAbsolutePath(),
|
file.getAbsolutePath(),
|
||||||
this.remote_file_path,
|
this.remote_file_path,
|
||||||
file.getName(),
|
file.getName(),
|
||||||
this.archive_path);
|
this.archive_path);
|
||||||
ssh.sendFileSSH();
|
ssh.sendFileSSH();
|
||||||
} else if (this.transfer_protocol.equals("FTP")) {
|
} else if (this.transfer_protocol.equals("FTP")) {
|
||||||
|
|
||||||
FTPProtocol ftp =
|
FTPProtocol ftp = new FTPProtocol(
|
||||||
new FTPProtocol(
|
this.user,
|
||||||
this.user,
|
this.password,
|
||||||
this.password,
|
bankHost,
|
||||||
bankHost,
|
this.port,
|
||||||
this.port,
|
file.getAbsolutePath(),
|
||||||
file.getAbsolutePath(),
|
this.remote_file_path,
|
||||||
this.remote_file_path,
|
file.getName(),
|
||||||
file.getName(),
|
this.archive_path);
|
||||||
this.archive_path);
|
ftp.sendFileFTP();
|
||||||
ftp.sendFileFTP();
|
} else {
|
||||||
} else {
|
|
||||||
|
System.out.println("Invalid TRANSFER_PROTOCOL. Must be one of FTP or SSH");
|
||||||
System.out.println("Invalid TRANSFER_PROTOCOL. Must be one of FTP or SSH");
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -9,157 +9,157 @@ import java.util.Vector;
|
|||||||
import com.moveFile.Movefile;
|
import com.moveFile.Movefile;
|
||||||
|
|
||||||
public class SSHProtocol {
|
public class SSHProtocol {
|
||||||
String user;
|
String user;
|
||||||
String password;
|
String password;
|
||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
String local_fileName;
|
String local_fileName;
|
||||||
String remote_filePath;
|
String remote_filePath;
|
||||||
String remote_fileName;
|
String remote_fileName;
|
||||||
String archive_path;
|
String archive_path;
|
||||||
String local_folder_path_bkp;
|
String local_folder_path_bkp;
|
||||||
|
|
||||||
public SSHProtocol(
|
public SSHProtocol(
|
||||||
String user,
|
String user,
|
||||||
String password,
|
String password,
|
||||||
String host,
|
String host,
|
||||||
int port,
|
int port,
|
||||||
String local_fileName,
|
String local_fileName,
|
||||||
String remote_filePath,
|
String remote_filePath,
|
||||||
String remote_fileName,
|
String remote_fileName,
|
||||||
String archive_path) {
|
String archive_path) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.local_fileName = local_fileName;
|
this.local_fileName = local_fileName;
|
||||||
this.remote_filePath = remote_filePath;
|
this.remote_filePath = remote_filePath;
|
||||||
this.remote_fileName = remote_fileName;
|
this.remote_fileName = remote_fileName;
|
||||||
this.archive_path = archive_path;
|
this.archive_path = archive_path;
|
||||||
}
|
|
||||||
|
|
||||||
public void sendFileSSH() {
|
|
||||||
try {
|
|
||||||
System.out.println("Going to SEND files from remote Server via SSH");
|
|
||||||
JSch jsch = new JSch();
|
|
||||||
System.out.println(
|
|
||||||
"Creating SSH Session: user@host:port |--->"
|
|
||||||
+ this.user
|
|
||||||
+ "@"
|
|
||||||
+ this.host
|
|
||||||
+ ":"
|
|
||||||
+ this.port);
|
|
||||||
Session session = jsch.getSession(this.user, this.host, 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.");
|
|
||||||
System.out.println(
|
|
||||||
"SFTP -- Local File Name: "
|
|
||||||
+ this.local_fileName
|
|
||||||
+ " Remote File Name: "
|
|
||||||
+ this.remote_fileName);
|
|
||||||
|
|
||||||
String[] fileTokens = this.remote_fileName.split("-");
|
|
||||||
|
|
||||||
System.out.println(
|
|
||||||
"Going to create brancheise folder:" + fileTokens[0] + " at " + this.remote_filePath);
|
|
||||||
sftpChannel.cd(this.remote_filePath);
|
|
||||||
try {
|
|
||||||
sftpChannel.mkdir(fileTokens[0]);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("Folder not created: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
sftpChannel.cd(fileTokens[0]);
|
|
||||||
|
|
||||||
sftpChannel.put(this.local_fileName, fileTokens[1]);
|
|
||||||
System.out.println("File copied to remote server Successfully, archiving file");
|
|
||||||
|
|
||||||
Movefile mv = new Movefile();
|
|
||||||
mv.movefile(new File(this.local_fileName), this.archive_path);
|
|
||||||
System.out.println("File archived to: " + this.archive_path);
|
|
||||||
sftpChannel.disconnect();
|
|
||||||
session.disconnect();
|
|
||||||
System.out.println("Disconnect SFTP Channel");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void fetchFileSSH(String remote_report_pattern) {
|
public void sendFileSSH() {
|
||||||
try {
|
try {
|
||||||
String local_folder_path_bkp = "/home/ec2-user/PRODFILES/reportFiles/processed_bkp";
|
System.out.println("Going to SEND files from remote Server via SSH");
|
||||||
System.out.println("Going to FETCH files from remote Server");
|
JSch jsch = new JSch();
|
||||||
JSch jsch = new JSch();
|
|
||||||
System.out.println(
|
|
||||||
"Creating SSH Session: user@host:port |--->"
|
|
||||||
+ this.user
|
|
||||||
+ "@"
|
|
||||||
+ this.host
|
|
||||||
+ ":"
|
|
||||||
+ this.port);
|
|
||||||
Session session = jsch.getSession(this.user, this.host, 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(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(
|
System.out.println(
|
||||||
"File: " + subDirFiles.getFilename() + " already present in local path");
|
"Creating SSH Session: user@host:port |--->"
|
||||||
}
|
+ this.user
|
||||||
}
|
+ "@"
|
||||||
}
|
+ this.host
|
||||||
|
+ ":"
|
||||||
|
+ this.port);
|
||||||
|
Session session = jsch.getSession(this.user, this.host, this.port);
|
||||||
|
session.setPassword(this.password);
|
||||||
|
|
||||||
sftpChannel.disconnect();
|
Properties config = new Properties();
|
||||||
session.disconnect();
|
config.put("StrictHostKeyChecking", "no");
|
||||||
System.out.println("Disconnect SFTP Channel");
|
session.setConfig(config);
|
||||||
} catch (Exception e) {
|
System.out.println("Establishing Connection...");
|
||||||
e.printStackTrace();
|
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.");
|
||||||
|
System.out.println(
|
||||||
|
"SFTP -- Local File Name: "
|
||||||
|
+ this.local_fileName
|
||||||
|
+ " Remote File Name: "
|
||||||
|
+ this.remote_fileName);
|
||||||
|
|
||||||
|
String[] fileTokens = this.remote_fileName.split("-");
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Going to create brancheise folder:" + fileTokens[0] + " at " + this.remote_filePath);
|
||||||
|
sftpChannel.cd(this.remote_filePath);
|
||||||
|
try {
|
||||||
|
sftpChannel.mkdir(fileTokens[0]);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Folder not created: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
sftpChannel.cd(fileTokens[0]);
|
||||||
|
|
||||||
|
sftpChannel.put(this.local_fileName, fileTokens[1]);
|
||||||
|
System.out.println("File copied to remote server Successfully, archiving file");
|
||||||
|
|
||||||
|
Movefile mv = new Movefile();
|
||||||
|
mv.movefile(new File(this.local_fileName), this.archive_path);
|
||||||
|
System.out.println("File archived to: " + this.archive_path);
|
||||||
|
sftpChannel.disconnect();
|
||||||
|
session.disconnect();
|
||||||
|
System.out.println("Disconnect SFTP Channel");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public void fetchFileSSH(String remote_report_pattern) {
|
||||||
|
try {
|
||||||
|
String local_folder_path_bkp = "/home/ec2-user/PRODFILES/reportFiles/processed_bkp";
|
||||||
|
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.host
|
||||||
|
+ ":"
|
||||||
|
+ this.port);
|
||||||
|
Session session = jsch.getSession(this.user, this.host, 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(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user