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

I eventually gave up and used FTP instead using Packages.org.ftp4che. If you really need SFTP then you should find a solution with the MID Server.

Ok, thank you.

Did you find the way to connect to SFTP?