With NetSuite's SuiteScript 2.0 you have the ability to access ssh servers, commonly known as secure FTP or SFTP.
You can upload or download files from an SFTP server. It is not possible to send files to NetSuite using the SFTP module. If you are looking for that, you can use a RESTLet.
If you are sure, SFTP is the answer to your question, we have a little bit of help for you here:
While URL, Port, Folder name and password are relatively easy to get (just ask the administrator of the service), you might not easily get the host key.
In a Windows command shell or on a Mac in terminal, run this command:
ssh-keyscan -t rsa -p [port] [host]
This is a unique identifier which the SFTP Module needs to create a connection with the remote server. Just copy the script below and enter the internal ID of the script which will later handle the connection and the domain. (restrictToScriptIds and restrictToDomains). Deploy it as a SuiteLet and run it through the link you find in the deployment.
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/log'],
function (serverWidget, log) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({
title: 'Guid Form'
});
form.addField({
id: 'username',
type: serverWidget.FieldType.TEXT,
label: 'Username'
});
form.addCredentialField({
id: 'password',
label: 'Password',
restrictToScriptIds: 'customscript_internal_id',
restrictToDomains: 'host of service'
});
form.addSubmitButton({
label: 'Submit Button'
});
context.response.writePage(form);
return;
} else {
var requset = context.request;
var myPwdGuid = requset.parameters.password;
log.debug("myPwdGuid", myPwdGuid);
context.response.write(myPwdGuid);
}
}
return {
onRequest: onRequest
};
}
);
The second script handles sending your file to the remote server. This is a workflow action script. You can modify it to be a module and pass sftp credentials and a file.
/**
*@NApiVersion 2.x
*@NScriptType WorkflowActionScript
*/
define(['N/sftp', 'N/file', 'N/search'],
function (sftp, file, search) {
function onAction(context) {
var txn = context.newRecord;
try {
var myPwdGuid = "WHAT YOUR SUITELET CREATED";
var myHostKey = "WHAT YOU FOUND FROM SSH-KEYSCAN";
var connection = sftp.createConnection({
username: 'YOUR USERNAME',
passwordGuid: myPwdGuid,
url: 'SERVICE DOMAIN',
port: PORT OF SERVICE IS USUALLY 22,
directory: 'FOLDER',
hostKey: myHostKey
});
var uploadFile = file.load({
id: 'PATH TO SOME FILE'
});
connection.upload({
filename: fileName,
file: uploadFile,
replaceExisting: true
});
}
}
return {
onAction: onAction
}
}
);