Supported SuiteScript File Types

Written by
Manuelito Macalinao
Published on
October 31, 2023 at 1:37:29 AM PDT October 31, 2023 at 1:37:29 AM PDTst, October 31, 2023 at 1:37:29 AM PDT

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 asfile.create(options)orConnection.download(options).

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

Note thatConnection.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

Its 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 (seeN/crypto Module).

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

Syntax

require(['N/sftp','N/file'],function(sftp, file){var connection = sftp.createConnection({/* The 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=="});/* Creating a simple file. */var myFileToUpload = file.create({ name:'originalname.js', fileType: file.Type.PLAINTEXT, contents:'I am a test file. Hear me roar.'});/* Uploading 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',/* The 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',/* The name of the file within the above directory on the external SFTP server which to download. */ filename:'downloadMe.js'});});