is there a way to download Excel files (.xlsx) fro...
# ask-stanley-ai
m
is there a way to download Excel files (.xlsx) from SFTP via SuiteScript? if yes, please give me the code get the file and save it as an Excel file
c
AI generated answer (using internal Slack threads):
Yes, you can download Excel files (.xlsx) from SFTP via SuiteScript. You can use the 'N/sftp' module in SuiteScript to accomplish this. Here is a basic example of how you can use the 'N/sftp' module to download a file:
Copy code
javascript
var sftp = require('N/sftp');
var file = require('N/file');

// Create connection
var connection = sftp.createConnection({
    username: 'username',
    passwordGuid: 'passwordGuid',
    url: '<sftp://hostname>',
    hostKey: 'hostKey'
});

// Download file
var downloadedFile = sftp.download({
    directory: '/path/to/directory',
    filename: 'filename.xlsx',
    fileType: file.Type.EXCEL,
    connection: connection
});

// Save file to file cabinet
var fileObj = file.create({
    name: 'filename.xlsx',
    fileType: file.Type.EXCEL,
    content: downloadedFile,
    folder: 'folderId'
});

fileObj.save();
Please replace 'username', 'passwordGuid', 'hostname', 'hostKey', 'path/to/directory', 'filename.xlsx', and 'folderId' with your actual values. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825444341
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.82463932
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824524462
Please provide your feedback on this answer.