Managing files and data securely is critical for businesses using NetSuite. Whether it’s importing large datasets, exporting reports, or integrating with external systems, ensuring data privacy and reliability is a top priority. The NetSuite Secure File Transfer Protocol (SFTP) module provides a robust solution for secure file exchanges, allowing companies to automate and streamline their file transfer processes while maintaining compliance and security standards. With SFTP, businesses can reduce manual errors, control access, and manage large volumes of data efficiently.
What Is the NetSuite SFTP Module?
The NetSuite SFTP Module is a built-in feature that enables secure file transfers between NetSuite and external servers. It uses industry-standard encryption protocols to ensure that sensitive data is transmitted safely.
Key aspects of the SFTP module include:
- Secure Data Transfers – Supports encrypted file uploads and downloads using SFTP protocols.
- Automation Capabilities – Can be integrated with SuiteScript to schedule file transfers and automate workflows.
- Access Control – Allows role-based permissions to manage who can send or receive files.
- Logging and Tracking – Provides audit logs for compliance and troubleshooting purposes.
- Integration Friendly – Works seamlessly with third-party applications and external servers for data exchange.
In short, the SFTP module in NetSuite ensures that your file transfers are secure, reliable, and fully auditable, making it an essential tool for businesses handling sensitive or high-volume data.
Learn more about NetSuite modules here.
SuiteScript API 2016.2
SuiteScript API 2016.2 has introduced a new feature, which enables a direct connection between SFTP servers and NetSuite. Skipping the middleware server previously required for SuiteScript API 1.0 has the advantage of not only decreased dependency but also a more efficient and timely process. However, this new model does have some shortcomings, such as:
- The inability to list the contents of a remote directory
- The requirement of a supported server for encryption algorithms and the consequent inability to support all types of servers
- Ineffectiveness connecting to FTP or FTPS
- Lack of access to the server’s host key in the NetSuite environment
NetSuite has approved the algorithms AES256-ctr, AES192-ctr, and AES128-ctr for connectivity. Therefore, the server can use the following encryption algorithms
- AES 128-CTR
- AES 192-CTR
- AES 256-CTR
Using the SFTP module
The following steps will help connect to an SFTP server using the SFTP module:
Generate the host-key of the SFTP server
The SFTP server’s host key can be generated through the following command:
Ssh-keyscan hostname or IP address
Generate a GUID in NetSuite
The Global Unique Identifier can be generated in NetSuite using a particular algorithm. Through this algorithm, a GUID can be generated for a particular domain or script.
An example of a sample code snippet for generating a GUID is the following:
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_id, //id of Script Using sftp
restrictToDomains: ‘domain name'
});
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
};
});
Create Connection To Your Server
The connection can be created in either the same GUID generator script or in an entirely new script. The sample code for the connection is as follows:
function mainFunc(context) {
var myHostKey = "Your Host-Name”;
var connection = sftp.createConnection({
username: 'root',
passwordGuid: "Guid generates from suitelet”,
url: 'sample url’,
directory: '/',
hostKey: myHostKey,
port: 22
});
Furthermore, the STFP module must be loaded to connect to a remote FTP server via SFTP and transfer files.
Upload And Download File as per your requirement
Finally, the file to upload to the path of the server can be created using the code given below:
var myFileToUpload = file.create({
name: 'file.txt',
fileType: file.Type.PLAINTEXT,
contents: 'This is uploaded using sftp API in SuiteScript 2.0'
});
connection.upload({
directory: '/',
filename: file.txt',
file: myFileToUpload,
replaceExisting: true
});
Files can also be downloaded from the directory of the server to the file cabinet in NetSuite through the following function:
var downloadedFile = connection.download({
directory: '/',
filename: file.txt'
});
downloadedFile.folder = folder id in which you want to place your file in file cabinet;
var fileId = downloadedFile.save();
Uploading and Downloading Files via SFTP
NetSuite allows businesses to securely transfer files using the SFTP module. You can perform transfers manually through NetSuite’s UI or automate them using SuiteScript.
Step 1: Manual File Transfers
- Navigate to Setup → Integration → SFTP Connections.
- Create a new SFTP connection or select an existing one.
- Use the File Cabinet → Import/Export options to upload or download files.
- Ensure the correct folder path and access permissions are set.
- Validate file transfer by checking the Execution Log.
Step 2: Automating Transfers with SuiteScript
Automation is done using the N/sftp module in SuiteScript 2.x. It allows scripted uploads and downloads directly to/from an SFTP server.
Example: Upload a file to SFTP
define(['N/sftp', 'N/file'], function(sftp, file) {
function uploadFile() {
var sftpConnection = sftp.createConnection({
username: 'USERNAME',
host: 'sftp.example.com',
port: 22,
keyId: 'CUSTOM_KEY_ID',
directory: '/uploads/'
}); var fileObj = file.load({id: '123'}); // Load file from NetSuite File Cabinet sftpConnection.upload({
directory: '/uploads/',
filename: fileObj.name,
file: fileObj.getContents()
}); log.debug('Upload Status', 'File uploaded successfully');
} return { execute: uploadFile };
});
- You can also download files similarly using
sftpConnection.download(). - Automate by scheduling this script as a Scheduled or Map/Reduce script.
Integrating SFTP with SuiteScript
SuiteScript integration ensures seamless file movement between NetSuite and external systems.
Using N/file and N/sftp Modules
N/file→ Handles NetSuite File Cabinet operationsN/sftp→ Handles SFTP connection and transfers- Combine them to read a file from NetSuite and upload it to an external SFTP or download from SFTP into NetSuite
Sample SuiteScript 2.0: Download a file from SFTP
define(['N/sftp', 'N/file'], function(sftp, file) {
function downloadFile() {
var sftpConnection = sftp.createConnection({
username: 'USERNAME',
host: 'sftp.example.com',
port: 22,
keyId: 'CUSTOM_KEY_ID'
}); var downloadedContent = sftpConnection.download({
directory: '/incoming/',
filename: 'data.csv'
}); var newFile = file.create({
name: 'data.csv',
fileType: file.Type.CSV,
contents: downloadedContent,
folder: 123 // Folder ID in File Cabinet
}); newFile.save();
log.debug('Download Status', 'File downloaded and saved in File Cabinet');
} return { execute: downloadFile };
});
Scheduling Automated Transfers
- Use Scheduled Scripts for fixed intervals (daily, hourly).
- Use Map/Reduce Scripts for processing large volumes of files efficiently.
Troubleshooting SFTP Connections
Even with correct setup, some issues may occur.
Common Problems & Fixes:
- Connection Refused → Check host, port, and firewall settings.
- Authentication Failed → Verify the SSH key ID, private key, or username.
- Permission Denied → Ensure proper folder access on the SFTP server.
- Timeouts or Large File Failures → Increase script governance limits or break files into smaller batches.
Tips:
- Enable debug logging in SuiteScript to track issues.
- Test connections in a sandbox environment before production deployment.
FAQs
1. Can SFTP transfers be automated in NetSuite?
Yes. Using SuiteScript 2.x, you can automate uploads and downloads and schedule them as Scheduled or Map/Reduce scripts.
2. How do I monitor failed transfers?
- Check the Execution Log for the script running the SFTP connection.
- Use SuiteScript
try-catchblocks to capture errors and send email notifications.
3. Can I transfer large files via SFTP?
Yes, but large files may require Map/Reduce scripts or chunked uploads to avoid governance or timeout limits.
4. What authentication methods does NetSuite SFTP support?
- SSH Key-based authentication (recommended)
- Username/Password (less secure, not recommended)
5. Can I use SFTP to integrate with external ERP or CRM systems?
Absolutely. NetSuite SFTP is integration-friendly and works with third-party systems for importing/exporting data securely.
To learn more about how to get the most out of your NetSuite investment, contact our trained NetSuite specialists for a free consultation.