How to send a file using SFTP

Michael Dziubin
Kilo Contributor

I want to send a csv file from ServiceNow to other server using SFTP. I tried j2ssh package:

var ssh = Packages.com.sshtools.j2ssh.SshClient(); 
var ignore = Packages.com.sshtools.j2ssh.transport.IgnoreHostKeyVerification(); 
var pwd = Packages.com.sshtools.j2ssh.authentication.PasswordAuthenticationClient();
pwd.setUsername(this.username);
pwd.setPassword(this.password);

var properties = Packages.com.sshtools.j2ssh.configuration.SshConnectionProperties();
properties.setHost(this.hostname);
properties.setPort(this.port);
var output = Packages.java.io.ByteArrayOutputStream();

ssh.connect(properties, ignore);

At first I tried to establish SSH connection and then switch to SFTP but I'm always getting error at ssh.connect line:

Evaluator: com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete

Any advice how to connect to an SFTP? Maybe there are other packages for it in ServiceNow, btw I don't have a Mid-Server.

12 REPLIES 12

Hi 

then for this purpose maybe you need a mid server.

Thanks 🙂

Is it impossible to do it without a mid server? My corporation doesn't intend to add a mid server to prod instance.

Hi 

I dont think so because if you are trying to send something through web to another location. It needs a mid server as far as my knowledge. 

Thanks 🙂

Links are not opening giving error

harinalamalapu
Giga Expert

Hi Michael,

Did you figure out a way around to establish SSH connection to push file to SFTP server ? I am trying to achieve the exact thing, and I am facing the same error as yours -

Evaluator: com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete