Thursday, 11 August 2016

Sync files from Acumatica to FTP server

Hi Everyone,

In Acumatica for every file you have in the database you may enable exporting or importing it to several supported protocols:
  • Shared Folder
  • FTP
  • HTTP
* Unfortunately HTTP protocol is supported only for downloading.

Today I want to share with you configuration and usage flow of file synchronizations based on File Transfer Protocol (FTP). Please be sure you have one if you want to complete this exercise.
All acumatica files should be attached to one or multiple entities. So you can find files attached to one particular document/line or you also can use search in files screen:

If you select single file will be able to see some configuration as well as other important information such as versions, security and synchronization.
Lets speak about synchronization in details.

Configuration
To configure synchronization you need to configure minimum 4 required fields:
  • Sync Type - Choose FTP server here.
  • Path - full path to the file on FTP server
  • Login - FTP server login.
  • Password - FTP server password
"Path" here is most tricky parameter, lets discuss it in details.

First of all it should contains the full path to the place where file should be on the end server. So the name of FTP server should be included into path.
For example if server has name Server, there is folder with name Folder and file with name File.xlsx, than the full path will be: ftp://server/folder/file.xlsx Acumatica will automatically determine the sever name based on the path. You also may include IP address or port in the path if you server has specific configuration.

Another important point is the how files from FTP server and Acumatica are linked to each other. In general you are using this screen to manage single file, so it usually it should be exported to one singe file on the FTP server. But this is not only one possible way. You also have a versions of a file, so you may want to export them as well, in this case single file in Acumatica will represents multiple files on FTP server. So based on path (is it end file or folder) Acumatica will do synchronization differently:
  • If you specify path to file with extension (ex: ftp://server/folder/file.xlsx) Acumatica will do 1 to 1 synchronization between database and FTP server. You also may notice that Acumatica automatically uncheck flag "Synchronize Folder Content".
  • If you specify path to the folder (ex: ftp://server/folder/) without extension or with "/" in the end, Acumatica will do synchronization with multiple files in the folder. You also may notice that Acumatica automatically check flag "Synchronize Folder Content". In this case during export Acumatica will export all existing versions of file to multiple physical files on the FTP server. It also works and visa-verse - during import Acumatica will import multiple files to multiple versions of one single database file.

Advanced Configuration and Tips
In case of synchronizing of folder content you also may control how Acumatica will name files on FTP server:
  • Based on revision id
  • Based version creation dated
Both of these parameters you can find on versions tab.

Also be careful when you importing files with "Sync Folder Content" flag. In this case Acumatica will get ALL files from the folder and will save it to database. Sometimes because of this you may have to much data in the database. Luckily you have a parameter "Import File Validation Mask" that is pure RegEx mask, that can be used for filtering incoming files.
During the importing of multiple files system will create versions in order to sequence how server returns list of files. In most case it is sorting by name, so pay attention on how you name files on FTP server.

Sync Process
During synchronization process Acumatica uses date time tags a lot, as this is only one flag that can help Acumatica to separate files that has been imported and what we need to import next.
This means that if you change date or time on your FTP server, you may have some issues with files that will be uploaded twice.

Also note that you always can schedule import&export process through dedicated processing screen - Fine Synchronization. Acumatica Automation Scheduler can run this process for you every required period of time.


How does it work
In the code it works based on standard .NET Web and Ftp Requests.
Also structure of providers are flexible and can be easily extended just based on adding new provider classes with customization.

Here I will provide you an example if FTP provider:

In the end I want to mention that all of sync parameters and configurations are valid and for Shared folder as well.

Have a nice configuration!

No comments: