1

I want to schedule a script on NetSuite to upload and download a txt file from an FTP location. I am able to create a file and store it in a file cabinet but that is as far as I can go.

I am a bit new and don't know if at all is it possible to have FTP scheduled from NetSuite?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nitin Chhajer
  • 2,299
  • 1
  • 24
  • 35

2 Answers2

2

Unfortunately, there is no FTP access to NetSuite.

You can work around that limitation with a scheduled script or web services however.

Here is a previous post with example code on how to start a scheduled script: How to upload a file to Netsuite File Cabinet Automatically?

  1. Place your CSV file into a location that is publicly visible(obviously, this only works if it's not sensitive information! PLEASE PLEASE PLEASE don't do this if you don't want the whole world to see it!)
  2. Create a scheduled script in NetSuite. Set the deployment to run daily, at whatever time you deem best
  3. In your scheduled script, use nlapiRequestUrl (NS help doc) to get the file from wherever you placed it (Note that there is a 5mb size limitation!)
  4. Use nlapiCreateFile (NS help doc) to create a file
  5. Use nlapiSubmitFile (NS help doc) to submit it to the file cabinet Sample code:

    var response = nlapiRequestURL('http://yourserver.yourcompany.com/somecsvfile.csv'); var csvDataInBase64 = response.getBody(); var file = nlapiCreateFile('mycsv.csv', 'CSV', csvDataInBase64); nlapiSubmitFile(file);

There is no error checking or anything in that sample, but it should get you started.

Community
  • 1
  • 1
xengravity
  • 3,501
  • 18
  • 27
  • 1
    Unfortunately there's no native mechanism for the FTP protocol in JavaScript or NS. You will need to instead use the HTTP protocol as @xengravity indicated. – erictgrubaugh Apr 27 '15 at 16:32
2

In SuiteScript 2.0 you can upload/download to SFTP locations using the N/sftp module. Here is a snippet of code I have used for a customer.

            var csvfile = file.create({
                'name': 'transactions.csv',
                'fileType': file.Type.CSV,
                'contents': filecontents
            });

            var conn = sftp.createConnection({
                'username': username,
                'passwordGuid': passwordGuid,
                'url': url,
                'directory': directory,
                'hostKey': hostkey
            });

            conn.upload({
                'file': csvfile,
                'replaceExisting': true
            });
Adam
  • 156
  • 1
  • 3