cancel
Showing results for 
Search instead for 
Did you mean: 

Connect sftp through python script

Mahesh7225
New Contributor

Hello,
Can you please help me to how to connect ftp server using python script in snaplogic

Thanks
Mahesh

6 REPLIES 6

Hi

Still i am facing issue to connect sftp server through script,
can anyone help me out to connect to sftp server through javascript or python.

Thanks in advance
Mahesh

Hello
i tried another code and still getting error “Reason: :42:4 Expected ; but found sftp let sftp = new Client(); ^ in ”

// Ensure compatibility with both JDK 7 and 8 JSR-223 Script Engines
try { load(“nashorn:mozilla_compat.js”); } catch(e) { }
// Import the interface required by the Script snap.
importPackage(com.snaplogic.scripting.language);
// Import the serializable Java type we’ll use for the output data.
importClass(java.util.LinkedHashMap);
var impl = {
input : input,
output : output,
error : error,
log : log,

execute : function () {
   this.log.info("Executing Transform Script");
    while (this.input.hasNext()) {
        try {

var Client = require(‘ssh2-sftp-client’);
let sftp = new Client();
sftp.connect({
host: ‘hostname’,
port: ‘22’,
username: ‘user1’,
password: ‘Password1’
}).then(() => {
return sftp.list(‘/files/upd/’);
}).then(data => {
console.log(data, ‘the data info’);
}).catch(err => {
console.log(err, ‘catch error’);
});
}
catch (err) {
var errDoc = new LinkedHashMap();
errDoc.put(“error”, err);
this.log.error(err);
this.error.write(errDoc);
}
}
this.log.info(“Script executed”);
},
cleanup : function () {
this.log.info(“Cleaning up”)
}
};

var hook = new com.snaplogic.scripting.language.ScriptHook(impl);