The N/sftp module enables SuiteScript to connect to remote SFTP servers and transfer files β both uploading and downloading. It is commonly used for EDI integrations, automated report delivery, and file-based data exchange.
Connecting to an SFTP Server
define(["N/sftp", "N/log"], (sftp, log) => {
const connection = sftp.createConnection({
username: "sftpuser",
passwordGuid: "custscript_sftp_password_guid",
url: "sftp.example.com",
port: 22,
directory: "/uploads",
hostKey: "AAAAB3NzaC1yc2EAAAA..." // Server host key
});
log.audit("SFTP connected", connection.url);
return {};
});
Uploading a File
const fileObj = file.load({ id: 12345 });
connection.upload({
directory: "/uploads",
filename: "export.csv",
file: fileObj,
replaceExisting: true
});
log.audit("File uploaded", "export.csv");
Downloading a File
const downloaded = connection.download({
directory: "/downloads",
filename: "incoming.csv"
});
const contents = downloaded.getContents();
log.debug("File content preview", contents.substring(0, 100));