Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

Опции темы Поиск в этой теме Опции просмотра
Старый 03.03.2017, 02:17   #1  
Blog bot is offline
Blog bot
24,249 / 809 (75) +++++++
Регистрация: 28.10.2006
stoneridgesoftware: Sending Flat Files from Dynamics 365 for Operations to a Different Location

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

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.

/// /// This method implements sftp functionality /// /// /// public void ftpFile() { str ftpAddress; str ftpLocation; str ftpUser; str ftpPW; SysFTPSiteInfo ftpInfo; System.Object ftpo; System.Object ftpResponse; System.Net.FtpWebRequest request; System.IO.StreamReader reader; System.IO.Stream requestStream; System.Byte[] bytes; System.Text.Encoding utf8; System.Net.FtpWebResponse response; System.Object credential; Filename fileType,fileNameString; FileName ftpFileName,fileName; new InteropPermission(InteropKind::ClrInterop).assert(); IntFilePathTable pathFile; // find the location where to save the file select firstonly pathFile; filePath = pathFile.FilePath; // get the ftp site info select firstonly ftpInfo; ftpAddress = ftpInfo.FTPSite; ftpLocation = ftpInfo.FTPFolder; ftpUser = ftpInfo.FTPUserId; < CODE REMOVED FOR READABILITY> // decrypt the password ftpPW = cryptography.decrypt(ftpInfo.FTPPassword); fileName localfileName = filePath + @'\' + expFileName; [filepath, filename, fileType] = fileNameSplit(localfileName); fileNameString= expFileName; ftpFileName = ftpAddress + '/' + ftpLocation + '/' + fileNameString; reader = new System.IO.StreamReader(localfileName); utf8 = System.Text.Encoding::get_UTF8(); bytes = utf8.GetBytes( reader.ReadToEnd() ); reader.Close(); // secure file transfer via SFTP using (var sftp = new Renci.SshNet.SftpClient(ftpAddress,ftpUser,ftpPW)) { sftp.Connect(); sftp.ChangeDirectory(@"/" + ftpLocation); using (var fileStream = new System.IO.FileStream(localfileName, System.IO.FileMode::Open)) { sftp.BufferSize = 4 * 1024; sftp.UploadFile(fileStream,expFileName,true,null); } } }

Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
atinkerersnotebook: Creating New Customer Notifications for Dynamics 365 for Operations using Flow and the Common Data Service Blog bot DAX Blogs 0 15.12.2016 22:12
NAV Team: Validating Single Sign-on with Office 365 and Microsoft Dynamics NAV 2013 R2 Blog bot Dynamics CRM: Blogs 0 19.12.2013 15:00
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
german_nav_developer: Buildnummern-Übersicht Microsoft Dynamics NAV 2009 Blog bot Dynamics CRM: Blogs 0 04.06.2010 13:21
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Часовой пояс GMT +3, время: 17:42.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.