Supported SuiteScript File Types

SuiteScript has two types of file objects: previously existing files in the NetSuite File Cabinet, and on demand files created using SuiteScript API calls such as file.create(options) or Connection.download(options).

File Cabinet and on demand files are supported by Connection.upload(options).

Note that Connection.download(options) returns an on demand file object. For an on demand file to be saved into the File Cabinet, it must receive a folder ID and be explicitly saved.

          ...

var downloadedFile = sftp.download({...});
downloadedFile.folder = 1234;
downloadedFile.save();

... 

        
Important:

It’s possible that a file you are downloading may be encrypted, or your SFTP provider may expect an uploaded file in a encrypted format in accordance with that provider's security practices. Make sure that you understand your provider's expectations and the cryptographic capabilities in SuiteScript (see N/crypto Module).

You can also create and remove directories. For more information, see N/sftp Module Members.

Syntax

          require(['N/sftp', 'N/file'], function (sftp, file) {
    var connection = sftp.createConnection({
         // Username supplied by the administrator of the external SFTP server.
         
         username: 'myuser',
         // Refers to the Password supplied by the administrator of the external SFTP server.
         // The Password Token/GUID obtained by reading the form POST parameter associated
         // with user submission of a form containing a Credential Field.
         // Value would typically be read from a custom field. 
         passwordGUID: "B34672495064525E5D65032D63B52301",
         
         // The URL supplied by the administrator of the external SFTP server.
         url: 'host.somewhere.com',
         
         // The SFTP Port number supplied by the administrator of the external SFTP server
         // defaults to 22).
         port: 22,

         // The transfer directory supplied by the administrator of the external SFTP server
         // (optional).
         directory: 'transferfiles',
         
         /* RSA Host Key obtained using the ssh-keyscan tool.

          $ ssh-keyscan -t rsa -p 22 host.somewhere.com

          AATpn1P9jB+cQx9Jq9UeZjA1245X7SBDcRiKh+Sok56VzSw==

          */

         hostKey: "AATpn1P9jB+cQx9Jq9UeZjA1245X7SBDcRiKh+Sok56VzSw=="
    });

    // Create a simple file.
    var myFileToUpload = file.create({
         name: 'originalname.js',
         fileType: file.Type.PLAINTEXT,
         contents: 'I am a test file. Hear me roar.'
    });

    // Upload the file to the external SFTP server.
    connection.upload({
         // Subdirectory within the transfer directory specified when connecting (optional).
          directory: 'relative/path/to/remote/dir',

         // Alternate file name to use instead of the one given to the file object (optional).
         filename: 'newFileNameOnServer.js',

         // File to upload.
         file: myFileToUpload,

         // If a file already exists with that name, replace it instead of failing the upload.
         replaceExisting: true
    });

    var downloadedFile = connection.download({
         //Subdirectory within the transfer directory specified when connecting (optional).
         directory: 'relative/path/to/file',
        
         // Name of the file within the above directory on the external SFTP server which
         // to download.
         filename: 'downloadMe.js'
    });
}); 

        

Related Topics

Setting up an SFTP Transfer
SFTP Authentication
Supported Cipher Suites and Host Key Types
N/sftp Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices