Pages

Friday, November 2, 2018

SFTP Management using WinSCP

đŸ‘‹ 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


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
 [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.....




7 comments:

  1. podrĂ­as compartir los objetos por favor. :)

    ReplyDelete
  2. Sorry, i didn't understand the language you speak, can you please let me know in English Language.

    ReplyDelete
  3. Any objects to download? Can't be found in the link. Thank you.

    ReplyDelete
  4. We do not have any objects, Reference are there while doing RND.

    ReplyDelete
  5. Great Work, Could you please share those objects.
    My Email id - kpradeep.ct@gmail.com

    ReplyDelete
  6. Hi good day. base on this solution you use Username and Password to authenticate the login, is it possible to use a SSH Key (Public/Private key) to authenticate the login? If yes can you share your solution please. Thank you in advance.

    ReplyDelete
    Replies
    1. did you find the solution for login via ssh private key

      Delete