Function to create SFTP connection

/**
         * @param ns_companyid
         * @param passwordGUID_SB
         * @param passwordGUID_LIVE
         * @param hostKey
         * Description -function to create Connection for SFTP
         */
        function createSFTPConnection(ns_companyid,passwordGUID_SB, passwordGUID_LIVE, hostKey)
        {
            let connection;
            //Connection establishment
            try {
                //Creating Connection to SB or RP account
                if (ns_companyid.indexOf('sb') > -1 || ns_companyid.indexOf('rp') > -1)
                {
                    connection = sftp.createConnection({
                        username: 'testns',
                        passwordGuid: passwordGUID_SB,
                        url: 'nsaf.bloomandgrowgroup.com',
                        hostKey: hostKey
                    });
                    log.debug("CONNECTION Object-SB", connection);
                    return connection;

                }
                else {
                    // Creating connection to Production account
                    connection = sftp.createConnection({
                        username: 'wms2',
                        passwordGuid: passwordGUID_LIVE,
                        url: 'nsaf.bloomandgrowgroup.com',
                        hostKey: hostKey
                    });
                    log.debug("CONNECTION Object -Prod", connection);
                    return connection;
                }
            } catch (error) {
                log.error("Error @connection establishment", error);
                consolidatedIF && record.submitFields({
                    type: "customrecord_itemfulfillment",
                    id: consolidatedIF,
                    values: {
                        "custrecord_jj_error": error.message,
                        "custrecord_jj_success": false
                    }
                });
                return false;
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *