How to use SNCSSH in MID Server Script Include
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi,
I have been using J2ssh library in mid server script include. However, the SFTP server no longer supports this encryption algorithm. I want to upgrade to SNCSSH. Can anyone let me know how to proceed with this.
The requirement is to push the CSV file from MID Server to target SFTP Server.
var SFTP = Class.create(); SFTP.prototype = { initialize: function() { this.File = Packages.java.io.File; this.J2ssh = Packages.com.sshtools.j2ssh; this.targetHost = probe.getParameter('host'); //hostname or IP address of the SFTP server this.targetPort = probe.getParameter('port'); this.targetUser = probe.getParameter('user'); this.targetPassword = probe.getParameter('password'); this.targetFile = probe.getParameter('target') + probe.getParameter('filename'); this.sourceFile = probe.getParameter('source') + probe.getParameter('filename'); this.deleteFile = probe.getParameter('deletefile'); }, fileTransfer: function() { try { this._sftp(); if (this.deleteFile) { this._deleteFile(); } } catch (ex) { ms.log('SFTP Error: ' + ex); } }, _authenticate: function(ssh) { var passwordAuth = new this.J2ssh.authentication.PasswordAuthenticationClient(); passwordAuth.setUsername(this.targetUser); passwordAuth.setPassword(this.targetPass); var result = ssh.authenticate(passwordAuth); if (result != new this.J2ssh.authentication.AuthenticationProtocolState().COMPLETE) { throw 'SFTP Authenticate Failed: ' + this.targetUser + '@' + this.targetHost + ':' + this.targetPort; } }, _deleteFile: function() { try { new this.File(this.sourceFile)['delete'](); } catch (ex) { throw 'SFTP Delete: ' + ex; } }, _sftp: function() { ms.log('SFTP Connect: ' + this.targetUser + '@' + this.targetHost + ':' + this.targetPort); var ssh = new this.J2ssh.SshClient(); try { ssh.connect(this.targetHost, this.targetPort, new this.J2ssh.transport.IgnoreHostKeyVerification()); this._authenticate(ssh); this._transfer(ssh); } catch (ex) { throw 'SFTP Error: ' + ex; } finally { ssh.disconnect(); } }, _transfer: function(ssh) { try { sftp = ssh.openSftpClient(); sftp.put(this.sourceFile, this.targetFile); ms.log('SFTP Transfer: ' + this.sourceFile + ' copied to ' + this.targetHost + ':' + this.targetPort); } catch (ex) { throw 'SFTP Transfer: ' + ex; } finally { sftp.quit(); } } };
Please let me know if the requirement can be achieved through any other way.
0 REPLIES 0