3

Hi I need to use the NetSuite sFtp Capability to create a file from a saved search and ftp'it to another server. I am wondering after the data that is returned how can I create the file and pass it to the FTP object? It will be a form of csv, can I add it say to the file cabinet and then access from there to pass to the FTP to then send it? Any help is very much appreciated thanks ;

SPS, sorry that would be SS2

jk121960
  • 843
  • 14
  • 45

2 Answers2

7

I created this tool to help quickstart your Suitescript 2.0 SFTP project. It makes getting the hostkey and passwordGUI a lot easier. I have the code and a tutorial video here.

Check it out here

Video Tutorial

Adolfo Garza
  • 2,966
  • 12
  • 15
5

NetSuites sFTP function requires a file.File in the file property of the options. The file could be a dynamic file like the NetSuite SuiteAnswers sample below (this is not my example, this is a SuiteAnswers Sample). Or the file could be a file loaded from the filing cabinet.

I really wish NetSuite would implement a native function to allow savedsearch results to be saved as CSV into the file cabinet as a file. This does not exist as of yet, so you will have to craft your own CSV file.

 /**
  *@NApiVersion 2.x
  */
 require(['N/sftp', 'N/file'],
     function(sftp, file) {
    var myPwdGuid = "B34672495064525E5D65032D63B52301";
    var myHostKey = "AAA1234567890Q=";

    var connection = sftp.createConnection({
        username: 'myuser',
        passwordGuid: myPwdGuid,
        url: 'host.somewhere.com',
        directory: 'myuser/wheres/my/file',
        hostKey: myHostKey
    });

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

    connection.upload({
        directory: 'relative/path/to/remote/dir',
        filename: 'newFileNameOnServer.js',
        file: myFileToUpload,
        replaceExisting: true
    });

    var downloadedFile = connection.download({
        directory: 'relative/path/to/file',
        filename: 'downloadMe.js'
    });
 });
scheppsr77
  • 577
  • 2
  • 12
  • Great that example is what I need, one question, the last code block would be for downloading what? Is that the file that I just uploaded to the server? thanks for all your help – jk121960 Oct 26 '16 at 19:12
  • The last block is an example of downloading a file from the ftp server. It does not pertain to your example/need. I just wanted it to show the full sample provided by NetSuite. – scheppsr77 Oct 26 '16 at 19:56
  • Is the connection automatically closed after use or should it be disposed of? – Charl Apr 16 '18 at 13:39