Sending Flat Files from Dynamics 365 for Operations to a Different Location

by | Updated January 3, 2018 | Development, Dynamics 365 for Finance and Operations

One of the challenges we have found with Dynamics 365 for Operations is the export of flat files. Recently we had to get data (as a flat file) out of Dynamics 365 for Operations and place it in a location for a separate system to process. The process had to be secure.

Initially, we were going to use the .NET Framework functionality for FTP-ing the data to an FTP site, but found that out of the box .NET does not provide the secure FTP functionality. There are many different options (some freeware, some paid). This discussion will implement a freeware version using SSH.NET (

The first step is to build the dll. Once built, a reference needs to be added to the Visual Studio project. One issue we found is that this reference needs to be in a location that will be available on all different environments (Development, UAT, and Production). We ended up copying the dll (Renci.SshNet.dll) to the AOS file structure, and placing it in the root of our Model (see screenshot below).

Flat files from Dynamics 365

This file was added to the Visual Studio project, and then added into version control. This allows the file to follow the project throughout the promotion of code.

The code below is part of a class that was created to allow the batching of the file upload process (which is called AFTER the file has been created and validated to exist). The code logs into the FTP site, and once successful uploads the file to the defined location.

All of the configuration information is stored in a custom table called SysFTPSiteInfo.

Below is the code for the ftp method used. Error trapping is NOT implemented in this demonstration code.


Related Posts


  1. rakesh

    This expects the file to be placed in a folder from where it uploads to FTP. Is there any way where we generate the content of the file dynamically and place it as a file in FTP ?

  2. Brandon Carmichael

    Hello Rakesh,

    Our example was not designed with the filestream in mind. But, if you can populate a filestream object with your data, it may be possible (We did not try this as were originally interested in opening the file and validating it). Based on this example, I think you could upload via the filestream object. I just have not tried to test/implement this:

    Hope this help,

  3. rakesh

    Hi Brandon,

    Thanks for your reply !!

    D365 being on Azure , what is the folder path (and server) you the pick the file from. I want to understand what is the value you pass to ‘localfileName’ with the understanding that we don’t have access to servers in the live environment


  4. Brandon Carmichael

    Hello Rakesh,

    I believe we used something like c:\windows\temp, as that is included by default with the OS. You will need to use something that is already there so you don’t create a new folder.


  5. Haja

    Can you please share the github source for download also with few more steps to configure in VS?

  6. Brandon Carmichael

    Hey Haja,

    Well, the source for the ftp dll was in the following article:
    Unfortunately I am not allowed to share out project, as this was created for a customer and not GitHub. If you need help with GitHub, I would suggest that you start here:

    Hope this helps,

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


06oct10:00 am10:30 amPreview of D365 Business Central Fall Release Features and Functionality

06oct12:00 pm12:30 pmInsider's Guide to New Features Available in the Fall Release of D365 Finance and Supply Chain

07oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Technical

13oct12:00 pm12:30 pmWave 2 Release – What’s Coming for Dynamics 365 Sales and Customer Service

21oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Functional

26oct(oct 26)9:00 am28(oct 28)5:00 pmStoneridge Connect Leadership and Community Conference


04nov11:00 am12:00 pmConfab LIVE with Stoneridge - Challenging the Development Paradigm

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!