👋 Hi all,
SFTP Management using WinSCP
Recently I have worked on a Website Integration where the requirement was to upload, download, Remove, & Move the files over SFTP and then send the Information to Website Team through REST/JSON API.
To achieve this goals I have created two modules.
1. Extract the Documents from NAV and then Upload, Download, Move & Remove over SFTP.
This module can be performed by SFTP Management Codeunit using WinSCP tools.
2. Send the information to Website so that they can manage (CRUD Operation) their database.
This module can be performed by Website Integration Mgt. Codeunit (Coming Soon).
WinSCP
WinSCP is an open source free SFTP client, FTP client, WebDAV client, S3 client and SCP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.
• Module 1:
Extract the Documents from NAV and then Upload, Download, Move & Remove over SFTP. This module can be performed by SFTP Management Codeunit using WinSCP tools.
Assume in NAV we have below objects
For better understanding please see the below Table structures:
Table 50065 Document Setup
SFTP Management using WinSCP
Recently I have worked on a Website Integration where the requirement was to upload, download, Remove, & Move the files over SFTP and then send the Information to Website Team through REST/JSON API.
To achieve this goals I have created two modules.
1. Extract the Documents from NAV and then Upload, Download, Move & Remove over SFTP.
This module can be performed by SFTP Management Codeunit using WinSCP tools.
2. Send the information to Website so that they can manage (CRUD Operation) their database.
This module can be performed by Website Integration Mgt. Codeunit (Coming Soon).
WinSCP
WinSCP is an open source free SFTP client, FTP client, WebDAV client, S3 client and SCP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.
• Module 1:
Extract the Documents from NAV and then Upload, Download, Move & Remove over SFTP. This module can be performed by SFTP Management Codeunit using WinSCP tools.
Assume in NAV we have below objects
For better understanding please see the below Table structures:
Table 50065 Document Setup
Table 50066 Document Category
Table 50067 Documents
Plan:
1. First of all I would like to extract the documents from NAV, To achieve this I have written a procedure namely [TryFunction] ExportDocument(DocNoP : Code[20])
2. Now Upload the Extracted document into SFTP.
To achieve this I have written a procedure namely
To achieve this I have written a procedure namely
[TryFunction] UploadFile(SourceFileP : Text)
3. To maintain history and sending data to website I have done some more work Like:
a. I have setup, if document is Create / Update / Delete in NAV then create a record in Send Items to Website Table with
SendItemstoWebsite."Process Status"::Pending
And once the document is uploaded in SFTP then SendItemstoWebsite."Process Status"::” “ should blank.
b. Now the second module is going to execute for sending the data to website using REST / JSON API.
4. To perform this you have to install WinSCP in server and copy the WinSCPnet.dll file from installed directory (C:\Program Files (x86)\WinSCP) and paste into NAV Service Add-Ins folder like: C:\Program Files\Microsoft Dynamics NAV\90\Service\Add-ins
Development:
Create a codeunit and declare the global variables as shown in below screenshot.
Create functions as shown as below screenshots
Please let me know if you have any queries.....