jk121960
jk121960

Reputation: 873

NetSuite sFtp of files

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

Upvotes: 3

Views: 4733

Answers (2)

Adolfo Garza
Adolfo Garza

Reputation: 3029

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

Upvotes: 7

scheppsr77
scheppsr77

Reputation: 577

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'
    });
 });

Upvotes: 5

Related Questions