NetSuite sFtp of files - sftp

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

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

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

Related

Need additional information on how to access an INDD file using JavaScript

I am trying to read a bulk of Adobe Indesign (indd) files and access its content through a script.
I want to check the name of drawing files present in the project and fetch that information in a flat file.
Can anybody help me with this as I am new to this technology?
If you are looking to read the bytes from the indd files, you cannot. The indd is a binary blob and no one knows what data is stored where.
If you are talking about getting list of placed files in the indd document, javascript can do that for you.
Step 1. Open the indd in indesign.
Step 2. the following script can return the path of each graphic in the doc
var grphx = app.activeDocument.allGraphics;
var i = 0;
for (i =0; i < grphx.length;++i)
{
alert(grphx[i].link.filePath);
}

How to create dynamic assets in Meteor

I thought this would be easy.
I want to create simple files the user can download by clicking a link.
Write what you want into the servers assets/app folder and then generate a simple link
Download> me!
Writing files into Meteor's server side asset folder is easy. And the download link above will always download a file with the name you specified.
You will get a yourNewFile.txt in the client's download folder. But, unfortunately its content will not be what you wrote on the server (new.txt).
Meteor has the strange behavior of downloading its startup html page as the content if the name of your content wasn't originally in the public folder. I think this is bug .... put the above anchor into a default Meteor project and click the link .. don't even create a public folder. You get a downloaded file with the name you asked for...
So, if you put stubs in the public folder (you know the names of the assets you are going to create) then you can create them dynamically.
I don't know the names before hand. Is there any way to get Meteor to 'update' its assets list with the new names I want to use?
I know there are packages that can do this. I'd like to just do it myself as above, really shouldn't be this hard.
The public/ folder intended use is specifically for static assets. Its content is served by the node http server.
If you want to dynamically generate assets on the server, you can rely on iron:router server side routes.
Here is a simple example :
lib/router.js
Router.route("/dynamic-asset/:filename",function(){
var filename = this.params.filename;
this.response.setHeader("Content-Disposition",
"attachment; filename=" + filename);
this.response.end("Hello World !");
},{
name: "dynamic-asset",
where: "server"
});
In server-side route controllers, you get access to this.response which is a standard node HTTP response instance to respond to the client with the correct server generated content. You can query your Mongo collections using the eventual parameters in the URL for example.
client/views/download/download.html
<template name="download">
{{#linkTo route="dynamic-asset" target="_blank" download=""}}
Download {{filename}}
{{/linkTo}}
</template>
client/views/parent/parent.html
<template name="parent">
{{> download filename="new.txt"}}
</template>
The linkTo block helper must be called in a context where the route parameters are accessible as template helpers. It will generate an anchor tag having an href set to Router.path(route, dataContext). It means that if our server-side route URL is /dynamic-asset/:filename, having a data context where filename is accessible and set to "new.txt" will generate this URL : /dynamic-asset/new.txt.
In this example we set the current data context of the download template to {filename: "new.txt"} thanks to the template invocation syntax.
Note that target="_blank" is necessary to avoid being redirected to the dynamic asset URL inside the current tab, and the download HTML attribute must be set to avoid considering the link as something the browser should open inside a new tab. The download attribute value is irrelevant as it's value will be overriden server-side.
Here is the raw Picker (meteorhacks:picker) route and method I used to get this running. I've kept it lean and its just what I got working and probably not the best way to do this ... the synchronous methods (like readFileSync) throw exceptions if things are not right, so they should be wrapped in try-catch blocks and the mkdirp is a npm package loaded through meteorhacks:npm package hence the Meteor.npmRequire. Thanks again to saimeunt for the directions.
Picker.route('/dynamic-asset/:filename', function(params, req, res, next) {
console.log('/dynamic-asset route!');
var fs = Npm.require('fs');
var path = Npm.require('path');
var theDir = path.resolve('./dynamic-asset');
var filename = params.filename;
var fileContent = fs.readFileSync(theDir + '/' + filename, {encoding:'utf8'});
res.end(fileContent);
});
The Meteor method that creates the file is
writeFile: function(fname, content) {
console.log('writeFile', fname);
var fs = Npm.require('fs');
var path = Npm.require('path');
var mkdirp = Meteor.npmRequire('mkdirp');
// verify/make directory
var theDir = path.resolve('./dynamic-asset');
mkdirp(theDir);
fs.writeFileSync(theDir + '/' + fname, content);
return 'aok';
}
and the hyper link I generate on the client if the file gets created looks like this:
Download lane file now
I incorrectly stated in my original question at the top that you could use stubs and write files into the assets folder. Its not so .. you will only get back the stub ... sorry.

Importing a JSON file in Meteor

I have a data.json file that I would like to load and that I have placed in the lib/ folder. What should I do in order to load that JSON into a variable in the server?
Thanks
There are three ways you can go about this, it depends what you're most comfortable with & your use case.
The first is to store it as a JS Object
if your json data is { "name":"bob" } you could use myjson = {"name":"bob"} in a .js file in the /lib folder and just call myjson when you need it.
Using an http call
You need the Meteor http package, installed via meteor add http.
Server Side code
myobject = HTTP.get(Meteor.absoluteUrl("/myfile.json")).data;
Client Side Code
HTTP.get(Meteor.absoluteUrl("/myfile.json"), function(err,result) }
console.log(result.data);
});
Another way to do it is to fetch the json file ajax style (you would have to put it in your /public folder though and use Meteor.http to call it.
Read the file directly
Lastly you could read the file directly, you store your myfile.json in a private directory in your project's root:
var myjson = {};
myjson = JSON.parse(Assets.getText("myfile.json"));
If you want to access this on the client side you would have to interface it with a Meteor.methods and Meteor.call
So whichever way you want, the first is the easiest but I'm not too sure how you want to use it or whether you want to pick the file or something
As I am new to all this I suspect this is not the correct way to do this, however this has worked for me...
Three coffee script files, two in the server directory:
server.coffee:
Meteor.startup ->
insertSample = (jsondata) ->
Fiber(->
Documents.insert
name: "Sample doc"
data: jsondata
).run()
if Documents.find().count() is 0
insertJSONfile("tests/test.json", insertSample)
and insertJSONfile.coffee:
fs = __meteor_bootstrap__.require("fs")
insertJSONfile = (file, insert) ->
jsondata = undefined
fs.readFile file, (err, data) ->
throw err if err
jsondata = JSON.stringify(JSON.parse(data))
insert(jsondata)
and model.coffee in the root dir:
#Documents = new Meteor.Collection("documents")
On startup this should load and insert the JSON file (in my case I've stored this in the tests directory) into a field in the documents collection.
I would love to hear from others on how this should be done properly.
I assume you want the json content to be represented as an object and not as a simple string.
I use js-yaml (https://github.com/nodeca/js-yaml), assuming you install the npm package. You can also just copy it manually.
yaml = __meteor_bootstrap__.require('js-yaml')
fs = __meteor_bootstrap__.require('fs')
content = fs.readFileSync(file, 'utf8')
object = yaml.load(content)
and that's it! I personally persist my json into meteor collections.

Is it possible to read data from an excel file without uploading it to the server in VB.Net?

I need to be able to read the data from an excel file and upload the data to a database after validating it.
However, the server I'm working with does not allow write privileges for the web applications, so I need to know if it is possible to read from an excel file without writing it to the server through upload?
So far I haven't been able to find a clear answer.
Thanks!
Let's say your upload control is called fileUpload.
You don't need to do a fileUpload.SaveAs("path"). You can read the stream with fileUpload.PostedFile.InputStream. I used this for a zip file with excel sheets in it (the library is Ionic by the way):
using (var file = ZipFile.Read(fileUpload.PostedFile.InputStream))
{
foreach (var zipEntry in file.Where(ze => ze.FileName.EndsWith(".xls")
|| ze.FileName.EndsWith(".xlsx")))
{
// process the Excel files here.
}
}
Sorry, I'm not very familiar with VB.net, so the following might be wrong. But because you asked for a VB.net version:
Using file As var = ZipFile.Read(fileUpload.PostedFile.InputStream)
For Each zipEntry As var In file.Where(ze => ze.FileName.EndsWith(".xls") or ze.FileName.EndsWith(".xlsx"))
' process the Excel files here.
Next
End Using

Saving a file in Flex Air

I'm trying to copy my SQLite file that is used in my Air app to user's selected directory using
var fileSaveDest:FileReference = new FileReference();
fileSaveDest.save(dbWorkedFile,'Inventory.DB');
dbWorkedFile is a File
dbWorkedFile = File.documentsDirectory.resolvePath("Inventory.db");
I tried this but the saved file isn't a valid SQLite file.
Also, I was wondering whether it's possible to embed SQLite to Air? If so how can I import and export the database?
Many thanks
In the end I couldn't get FileReference.save() to work so I go with the regular File's browseForSave()
dbWorkedFile.addEventListener(Event.SELECT, savingDatabase);
dbWorkedFile.browseForSave('Specify save location');
private function savingDatabase(event:Event):void
{
var selectedFile:File = File(event.target);
//To ensure the file is still loaded
dbWorkedFile = File.applicationStorageDirectory.resolvePath("Inventory.db");
dbWorkedFile.copyTo(selectedFile, true);
}
There is a short article describing how to include some SQLLite files in an AIR application on Adobe website (cookbooks section).

Resources