/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

define(['N/file', 'N/sftp', 'N/error'],
function(file, sftp, error) { 
    return {
        beforeLoad: function(){
            var portNumber = -1;
            var connectTimeout = -1;
            var transferTimeout = -1;
            //these variables can be taken as parameters of the script instead

            if (portNumber < sftp.MIN_PORT_NUMBER || portNumber > sftp.MAX_PORT_NUMBER)
                portNumber = sftp.DEFAULT_PORT_NUMBER;
            if (connectTimeout < sftp.MIN_CONNECT_TIMEOUT)
                connectTimeout = sftp.MIN_CONNECT_TIMEOUT;
            else if (connectTimeout > sftp.MAX_CONNECT_TIMEOUT)
                connectTimeout = sftp.MAX_CONNECT_TIMEOUT;

            var connection = sftp.createConnection({
                username: 'sftpuser',
                keyId: 'custkey1',
                url: '192.168.0.100',
                port: portNumber,
                directory: 'inbound',
                timeout: connectTimeout,
                hostKey: "AAAAB3NzaC1yc2EAAAADAQABAAABAQDMifKH2vTxdiype8nem7+lS3x7dTQR/A67KdsR/5C2WUcDipBzYhHbnG6Am12Nd2tlM01LnaBZA6/8P4Y9x/sGTxtsdE/MzeGDUBn6HBlQvgIrhX62wgoKGQ+P2lEAO1+Vz8y3/MB1NmD7Fc62cJ9Mu88YA6jwJOIPZeHYNVyIm9OrY6VyzYyvSJhH0x7SXyvGnijJQF4G8C4c8u/UVpF/sE16xKZtly2Rx0aDL2FsDRtpyPmM602/R6ISbsmgab3MzzAEIu+zLDMdIBJn3cDhNt1F7Rar6Tu0u18KCkk8GPxbnxDuG4sCNOnXPYkDXSMUbM/ocRjYGtqdZUMmeTf3"
            });

            // can also be a big file (created for example by async search)
            var myFileToUpload = file.create({
                name: 'originalname.txt',
                fileType: file.Type.PLAINTEXT,
                contents: 'I am a test file.'
            });

            if (myFileToUpload.size > connection.MAX_FILE_SIZE)
                throw error.create({name:"FILE_IS_TOO_BIG", message:"The file you are trying to upload is too big"});

            var minTransferTimeout = 10;
            if (transferTimeout > connection.MAX_TRANSFER_TIMEOUT)
                transferTimeout = connection.MAX_TRANSFER_TIMEOUT;
            else if (transferTimeout < minTransferTimeout)
                transferTimeout = minTransferTimteout;

            connection.upload({
                directory: 'files',
                filename: 'test.txt',
                file: myFileToUpload,
                replaceExisting: true,
                timeout: transferTimeout
            });
        }
    }; 
});
[{"tag": "IP_ADDRESS", "value": "192.168.0.100", "start": 927, "end": 940}, {"tag": "KEY", "value": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDMifKH2vTxdiype8nem7+lS3x7dTQR/A67KdsR/5C2WUcDipBzYhHbnG6Am12Nd2tlM01LnaBZA6/8P4Y9x/sGTxtsdE/MzeGDUBn6HBlQvgIrhX62wgoKGQ+P2lEAO1+Vz8y3/MB1NmD7Fc62cJ9Mu88YA6jwJOIPZeHYNVyIm9OrY6VyzYyvSJhH0x7SXyvGnijJQF4G8C4c8u/UVpF/sE16xKZtly2Rx0aDL2FsDRtpyPmM602/R6ISbsmgab3MzzAEIu+zLDMdIBJn3cDhNt1F7Rar6Tu0u18KCkk8GPxbnxDuG4sCNOnXPYkDXSMUbM/ocRjYGtqdZUMmeTf3", "start": 1082, "end": 1454}]
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

define(['N/file', 'N/sftp', 'N/error'],
function(file, sftp, error) { 
    return {
        beforeLoad: function(){
            var portNumber = -1;
            var connectTimeout = -1;
            var transferTimeout = -1;
            //these variables can be taken as parameters of the script instead

            if (portNumber < sftp.MIN_PORT_NUMBER || portNumber > sftp.MAX_PORT_NUMBER)
                portNumber = sftp.DEFAULT_PORT_NUMBER;
            if (connectTimeout < sftp.MIN_CONNECT_TIMEOUT)
                connectTimeout = sftp.MIN_CONNECT_TIMEOUT;
            else if (connectTimeout > sftp.MAX_CONNECT_TIMEOUT)
                connectTimeout = sftp.MAX_CONNECT_TIMEOUT;

            var connection = sftp.createConnection({
                username: 'sftpuser',
                keyId: 'custkey1',
                url: '192.168.0.100',
                port: portNumber,
                directory: 'inbound',
                timeout: connectTimeout,
                hostKey: "9q3vfhm7l33rus21toc8fndupq76itje"
            });

            // can also be a big file (created for example by async search)
            var myFileToUpload = file.create({
                name: 'originalname.txt',
                fileType: file.Type.PLAINTEXT,
                contents: 'I am a test file.'
            });

            if (myFileToUpload.size > connection.MAX_FILE_SIZE)
                throw error.create({name:"FILE_IS_TOO_BIG", message:"The file you are trying to upload is too big"});

            var minTransferTimeout = 10;
            if (transferTimeout > connection.MAX_TRANSFER_TIMEOUT)
                transferTimeout = connection.MAX_TRANSFER_TIMEOUT;
            else if (transferTimeout < minTransferTimeout)
                transferTimeout = minTransferTimteout;

            connection.upload({
                directory: 'files',
                filename: 'test.txt',
                file: myFileToUpload,
                replaceExisting: true,
                timeout: transferTimeout
            });
        }
    }; 
});
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

define(['N/file', 'N/sftp', 'N/error'],
function(file, sftp, error) { 
    return {
        beforeLoad: function(){
            var portNumber = -1;
            var connectTimeout = -1;
            var transferTimeout = -1;
            //these variables can be taken as parameters of the script instead

            if (portNumber < sftp.MIN_PORT_NUMBER || portNumber > sftp.MAX_PORT_NUMBER)
                portNumber = sftp.DEFAULT_PORT_NUMBER;
            if (connectTimeout < sftp.MIN_CONNECT_TIMEOUT)
                connectTimeout = sftp.MIN_CONNECT_TIMEOUT;
            else if (connectTimeout > sftp.MAX_CONNECT_TIMEOUT)
                connectTimeout = sftp.MAX_CONNECT_TIMEOUT;

            var connection = sftp.createConnection({
                username: 'sftpuser',
                keyId: 'custkey1',
                url: '192.168.0.100',
                port: portNumber,
                directory: 'inbound',
                timeout: connectTimeout,
                hostKey: "PI:KEY:9q3vfhm7l33rus21toc8fndupq76itjeEND_PI"
            });

            // can also be a big file (created for example by async search)
            var myFileToUpload = file.create({
                name: 'originalname.txt',
                fileType: file.Type.PLAINTEXT,
                contents: 'I am a test file.'
            });

            if (myFileToUpload.size > connection.MAX_FILE_SIZE)
                throw error.create({name:"FILE_IS_TOO_BIG", message:"The file you are trying to upload is too big"});

            var minTransferTimeout = 10;
            if (transferTimeout > connection.MAX_TRANSFER_TIMEOUT)
                transferTimeout = connection.MAX_TRANSFER_TIMEOUT;
            else if (transferTimeout < minTransferTimeout)
                transferTimeout = minTransferTimteout;

            connection.upload({
                directory: 'files',
                filename: 'test.txt',
                file: myFileToUpload,
                replaceExisting: true,
                timeout: transferTimeout
            });
        }
    }; 
});