Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

trying a sftp connection via java callout

Hi,

I'm trying to execute a java callout to connect to a sftp server. I'm using com.jcraft.jsch.JSch jar for connecting to the server. I did some trial and error and found that the callout is failing as i'm initializing the obect JSch jsch = new JSch();

There are no logs that i can provide here. Sample code that i have used is below:

JSch jsch = new JSch();

String knownHostsFilename = "/home/username/.ssh/known_hosts";
jsch.setKnownHosts( knownHostsFilename );

Session session = jsch.getSession( "remote-username", "remote-host" );    
{
  // "interactive" version
  // can selectively update specified known_hosts file 
  // need to implement UserInfo interface
  // MyUserInfo is a swing implementation provided in 
  //  examples/Sftp.java in the JSch dist
  UserInfo ui = new MyUserInfo();
  session.setUserInfo(ui);

  // OR non-interactive version. Relies in host key being in known-hosts file
  session.setPassword( "remote-password" );
}

session.connect();

Channel channel = session.openChannel( "sftp" );
channel.connect();

ChannelSftp sftpChannel = (ChannelSftp) channel;

sftpChannel.get("remote-file", "local-file" );
// OR
InputStream in = sftpChannel.get( "remote-file" );
  // process inputstream as needed

sftpChannel.exit();
session.disconnect();
Solved Solved
0 5 3,505
1 ACCEPTED SOLUTION

It's possible that constructor is doing something that Apigee Edge prohibits. If so your code would see a permissions exception and you'd be able to catch it and set a context variable containing the stack trace.

To avoid the limitation, I suggest doing the FTP bit in something like nodejs. Is that feasible?

View solution in original post

5 REPLIES 5