This topic contains 6 replies, has 0 voices, and was last updated by Lala Britney 6 years, 11 months ago.

  • Author
    Posts
  • #18099

    Lala Britney

    Hi 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.

  • #18100

    saenzmariano

    Hi 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.

  • #18101

    teddycaguioa

    Try 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.

  • #18102

    teddycaguioa

    Also, 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.

  • #18103

    teddycaguioa

    See 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?

  • #18104

    teddycaguioa

    What 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.

  • #18105

    Lala Britney

    Hi,

    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.

You must be logged in to reply to this topic.