简体   繁体   English

如何使用JavaScript将csv文件从NetSuite的文件柜传递到ftp服务器?

[英]How to pass the csv file from file cabinet in NetSuite to ftp server using JavaScript?

Could you help me do the task using JavaScript? 您能帮我使用JavaScript完成任务吗?

I have a task and if i do it manually it looks like this: 我有一个任务,如果我手动执行,则如下所示:

  1. i create Saved Search in NetSuite. 我在NetSuite中创建了“保存的搜索”。
  2. Download the result of created saved search in csv. 在CSV中下载创建的已保存搜索的结果。
  3. The i put this file on ftp server, using FileZilla. 我使用FileZilla将文件放在ftp服务器上。 (i had a connection with server previously: write a domain, username and password - that's all) (我以前与服务器建立了连接:输入域,用户名和密码-仅此而已)

Now, a need it solve through sutlet script. 现在,它需要通过sutlet脚本解决。 1. Create Saved Search - done 2. Create csv with result of saved search in content and put it in file cabinet in the NetSuite - done 3. Ok, now i have a needs me file but i do not understand how to pass it on ftp. 1.创建保存的搜索-完成2.创建带有保存内容搜索结果的csv,并将其放入NetSuite的文件柜中-完成3.好的,现在我需要一个文件,但是我不知道如何传递FTP。

*i tried to study several articles, but frankly speaking could not to solve my problem. *我试图研究几篇文章,但坦率地说无法解决我的问题。 Moreover, their article seems about manually method not automative 而且,他们的文章似乎是关于手动方法而不是自动方法

this aritcle - https://ursuscode.com/netsuite-tips/suitescript-2-0-sftp-tool/ * 这aritcle - https://ursuscode.com/netsuite-tips/suitescript-2-0-sftp-tool/ *

var searchResult = Contacts.run().getRange(0,999);
                log.debug('Contacts', searchResult);
                var Header = 'INTERNAL ID' + ';' + 'FIRST NAME' + ';' + 'LAST NAME';
                var Content = "";

                for (var i = 0; i < searchResult.length; i++) {

                    var internalid = searchResult[i].getValue('internalid');
                    var FirstName = searchResult[i].getValue('firstname');
                    var LastName = searchResult[i].getValue('lastname');

                    Content = Content + internalid + ';' 
                                + FirstName + ';'
                                + LastName; 
                    Content = Content + '\n';
                }

                var fileObj = file.create({
                    name: 'test.csv',
                    fileType: file.Type.CSV,
                    contents: Header + '\n' + Content
                    });
                    fileObj.folder = 45434;
                    var fileId = fileObj.save();

                    var savedFileObj = file.load({
                        id: fileId
                    });

                    var myPwGuid = '';
                    var myHostKey = ''
                    var objConnection = sftp.createConnection({
                        username: '',
                        passwordGuid: myPwGuid,
                        url: 'ftp.expertsender.com',
                        hostKey: myHostKey
                        });

NetSuite不支持ftp,它仅支持sftp。

NetSuite has the support for SFTP, FTP and SFTP runs in different port numbers, However FTP transfers data in plain text format which will compromise your security, using SFTP is the better option as it will transfer your data in encrypted format and security is assured. NetSuite支持在不同端口号上运行的SFTP,FTP和SFTP,但是FTP以纯文本格式传输数据会损害您的安全性,使用SFTP是更好的选择,因为它将以加密格式传输数据并确保安全性。

In your example, I believe you're calling FTP request which will not work in this case. 在您的示例中,我相信您正在调用FTP请求,在这种情况下将无法使用。

Oki, 好吧

Now, the article you did mention is the right one : why ? 现在,您提到的文章是正确的:为什么? Because the first required step to be able to use SFTP is to generate a GUID. 因为能够使用SFTP的第一步是生成GUID。 You are talking about manual methods, well yes, including the one in that Article, but it is not a problem, because once you have generated the GUID, you don't need to change it, so it is a one time action, unless your ftp credential change. 您正在谈论手动方法,是的,包括该文章中的方法,但这不是问题,因为一旦生成了GUID,就无需更改它,因此这是一次性的操作,除非您的ftp凭证更改。

So, first step : use "ursuscode" to create a Suitelet. 因此,第一步:使用“ ursuscode”创建Suitelet。 Deploy that suitelet and use it to generate the GUID (it is a form where you need to set the ftp password, host...). 部署该套件并使用它生成GUID(这是您需要设置ftp密码host的一种形式)。 Using the same form, you can then generate the HOST key (check the video). 然后,使用相同的表格可以生成HOST密钥(检查视频)。

Second step, use the Generated GUID and HOST Key in your code. 第二步,在代码中使用Generated GUID和HOST密钥。

Third step, add the code to upload the file : from netsuite help page, here is an example: 第三步,添加代码以从netsuite帮助页面上传文件:,这是一个示例:

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

By the way, you can upload the file without the need to Save and Reload it again ( https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4617004932.html ). 顺便说一句,您可以上传文件而无需再次保存并重新加载( https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4617004932.html )。

Note: remember that this is an SFTP, so probably support only SFTP not FTP. 注意:请记住,这是一个SFTP,因此可能仅支持SFTP,而不支持FTP。

Suggestion: About the GUID (and the other data needed for the connection), I suggest that you use a Script Parameter to provide the GUID to your script code, so if your password change, you can regenerate the GUID and update the script parameter value without the need to touch your code. 建议:关于GUID(以及连接所需的其他数据),我建议您使用脚本参数为脚本代码提供GUID,因此,如果密码更改,则可以重新生成GUID并更新脚本参数值无需触摸您的代码。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM