cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CPI File List through Groovy script with SCC in between

digirolamocristian60
Participant
632

Hi all,

As CPI doesn't come with any standard feature to list files in a directory, I'm using a Groovy script.

// initialize vars
def secureStorageService =  ITApiFactory.getApi(SecureStoreService.class, null);
	def cred = secureStorageService.getUserCredential(aliasCredentials);
	if (cred == null){
	// error handling
	}
	userName = cred.getUsername()
	password = new String(cred.getPassword())
	def exception = ''
	JSch jsch = new JSch();
	Session session = null;
	try {
		session = jsch.getSession(userName, hostName, Integer.valueOf(port));
		session.setConfig("StrictHostKeyChecking", "no");
		session.setPassword(password);
		session.connect();
		Channel channel = session.openChannel("sftp");
		channel.connect();
		ChannelSftp sftpChannel = (ChannelSftp) channel;
		InputStream stream = sftpChannel.get(filePath);
		sftpChannel.exit();
		session.disconnect();
	} catch(Exception e) {
		exception = e.getMessage()
		//Exception Handling 
	}
// output handling

It works as long as the SFTP server is on the internet. What if the server is reachable only through SCC? How can I make my Groovy script work?

Regards.

Cristian

Accepted Solutions (0)

Answers (0)