This topic contains 6 replies, has 0 voices, and was last updated by Lala Britney 6 years, 11 months ago.
-
AuthorPosts
-
December 13, 2017 at 1:58 am #18099
Lala BritneyHi All,
I am trying to establish a connection to our sftp server as we need to be able to upload and download files for a daily scheduled job.
Having gone through the help and forums for the new sftp module, I have taken tips and created a suitelet script for generating the pwdguid and storing it in a custom record. I am then reading this GUIDpwd and passing it to the sftp connection api along with the host key and the correct IP address. But I am getting error when trying to establish the connection.
Name: UNEXPECTED_ERROR Message: null
This error has no meaning so I am not able to debug it. Our Server Administrator has confirmed that this is the host key for the sftp server is correct which was generated using the ssh keyscan option on mac.
Has anybody else seen this error? Is there any other way to confirm this connection with the parameters being passed? Not sure but is there anything obvious that I am missing?
Any help appreciated. Please see my script below.
/**
* @NApiVersion 2.x
* @NScriptType Suitelet // will need to change to a scheduled script later.
* @NModuleScope SameAccount
*/
define([‘N/file’, ‘N/search’,’N/record’, ‘N/url’, ‘N/https’, ‘N/ui/serverWidget’, ‘N/sftp’, ‘N/error’, ‘N/log’,’N/encode’],
/**
* @param {file} file
* @param {search} search
* @param {record} record
* @param {ui} ui
* @param {sftp} sftp
* @param {error} error
* @param {url} url
*/
function(file, search, record, url, https, ui, sftp, error ) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request – Encapsulation of the incoming request
* @param {ServerResponse} context.response – Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
var myHostKey = “”;
function ftpUpload(pwdGuid){
myHostKey = “a very very long key”;
var connection = sftp.createConnection ({
username: ‘username’,
passwordGuid: pwdGuid,
hostKey: myHostKey,
directory: ‘/’,
url:”ip adress of sftp server”,
port:22
});
}
try
{
var GUIDrec = record.load({
type: ‘customrecord_ftp_credentials’,
id: 1,
isDynamic: true,
});
var pwdGuid = GUIDrec.getValue({fieldId: ‘custrecord_ftp_password’});
ftpUpload(pwdGuid);
context.response.write(‘CONNECTION SUCCESSFUL!’);
}
catch(error) {
context.response.write(‘ Name: ‘ + error.name + ‘n’);
context.response.write(‘ Message: ‘ + error.message + ‘n’);
context.response.write(‘ ID: ‘ + error.id + ‘n’);
context.response.write(‘ Stack: ‘ + error.stack + ‘n’);
context.response.write(‘PassGUID: |’ + pwdGuid + ‘|’);
context.response.write(‘HostKey: |’ + myHostKey + ‘|’);
}
}
return {
onRequest: onRequest
};
});
This is a cached copy. Click here to see the original post. -
December 13, 2017 at 10:24 am #18100
saenzmarianoHi Lala, this is not the correct forum for this question. I believe it should go here: https://usergroup.netsuite.com/users…-0-custom-code
Lala Britney replied on 12/13/2017, 05:58 PM: Sorry about that. Thanks for moving it to the correct place.
-
December 13, 2017 at 5:04 pm #18101
teddycaguioaTry setting the hostKeyType option when calling sftp.createConnection().
Lala Britney replied on 12/13/2017, 08:09 PM: yes have set it to use ‘rsa’ but still does not work.
-
December 13, 2017 at 5:07 pm #18102
teddycaguioaAlso, make sure to set properly the restrictToScriptIds and restrictToDomains options when calling form.addCredentialField()
Lala Britney replied on 12/13/2017, 08:15 PM: Thanks for your replying teddycaguioa .
for restrictToScriptIds I have added the script id of the suitelet which is using and passing the pwdguid stored in the custom record to eastablish the connection.
restrictToDomains is the IP Address of the sftp server to which am trying to connect.
Are these parameter values correct?
I can connect to the sftp thru filezilla or ftp voyager without any problems.
Is there a way I can test the connection using the hostkey and pwdguid?
Also, when would it throw an “unexpected error”? It is so frustrating as it does not give any indication of what could be wrong.
-
December 13, 2017 at 8:12 pm #18103
teddycaguioaSee this tool if it will help https://ursuscode.com/netsuite-tips/…2-0-sftp-tool/
Lala Britney replied on 12/13/2017, 11:45 PM: Thanks for the tool. I tried it but am not able to generate the Host key using the tool. It says “Server did not repsond”.
Our SFTP server is on AWS. Can we have a sftp connection between netsuite and a sftp server on AWS?
Also Can there be a firewall problem? Is there any way we allow netsuite (any ip address) access to the firewall?
-
December 13, 2017 at 8:20 pm #18104
teddycaguioaWhat is the type of the field you used to store the password? Try using a Long Text since a Free-Form Text might be too small and might truncate the generated password GUID.
-
December 18, 2017 at 7:57 pm #18105
Lala BritneyHi,
Just an update looks like there was a firewall issue, we could not allow netsuite urls on a ftp server on AWS. I was able to connect to a resident sftp server .
thanks for all your help.
-
AuthorPosts
You must be logged in to reply to this topic.