Forum Discussion
i tried this but still getting error “Reason: _socket.error: [Errno 111] Connection refused in ”
#from com.snaplogic.scripting.language import pysftp
#from import ScriptHook
from ftplib import FTP
from com.snaplogic.scripting.language import ScriptHook
from com.snaplogic.scripting.language.ScriptHook import *
myHostname = “hostname”
myUsername = “username”
myPassword = “password”
ftp = FTP(“hostname”,“22”)
ftp.login(“username”,“password”)"
- Mahesh72254 years agoNew Contributor
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- Mahesh72254 years agoNew Contributor
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);