I am succesfully connecting to an external SFTP site, and pulling some files into Netsuite using the "Connection.download" API. However, now I am trying to upload some files from the file cabinet using "Connection.upload", and the connection goes thru, but the file is not uploaded due to this error:
{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"id":"99fb0517-6f26-417c-aa90-94d056008d24-2d323032332e31302e3130","stack":["anonymous(N/file)","execute(/SuiteScripts/TSM Scripts/TSM - Export Inventory Stock File.js:25)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace":["anonymous(N/file)","execute(/SuiteScripts/TSM Scripts/TSM - Export Inventory Stock File.js:25)"],"notifyOff":false},"notifyOff":false,"userFacing":false}
Here is the Script I'm using:
//****************************************************************************
//** Connects to the sftp site and exports the FILE CSV
//** files from the File Cabinet
//****************************************************************************
/**
*@NApiVersion 2.x
*@NScriptType ScheduledScript
*/
define(["N/file", 'N/sftp'], function(file, sftp) {
function execute (context){
var password = "xxxxxxxxxxxxx";
var username = "xxxxxxxxxx";
var passwordGuid = "xxxxxxxxxxxxxxxxxx";
var url = "sftp.site.com";
var hostKey = "(PROPER HOSTKEY)";
var hostKeyType = "rsa";
var port = "22";
var location = "/DIRECTORY/";
var timeout = 0;
var sftpConnection = getSFTPConnection(username, passwordGuid, url, hostKey, hostKeyType, port, location, timeout);
var fileObj = file.load({
id: 1722969
});
try {
sftpConnection.upload({
directory: location,
file: fileObj,
replaceExisting: true
});
}
catch (e){
log.debug("Error on try", e)
}
}
function getSFTPConnection(username, passwordGuid, url, hostKey, hostKeyType, port, location, timeout){
var preConnectionObj = {};
preConnectionObj.passwordGuid = passwordGuid;
preConnectionObj.url = url;
preConnectionObj.hostKey = hostKey;
if(username){ preConnectionObj.username = username; }
if(hostKeyType){ preConnectionObj.hostKeyType = hostKeyType; }
if(port){ preConnectionObj.port = Number(port); }
if(location){ preConnectionObj.directory = location; }
if(timeout){ preConnectionObj.timeout = Number(timeout); }
var connectionObj = sftp.createConnection(preConnectionObj);
return connectionObj;
}
return{
execute: execute
};
});
Any help will be appreciated