Friday, June 7, 2019

SFTP File Upload via x++

I recently had a requirement to create a batch job that would upload a file to an SFTP server daily.  AX 2012 was not capable of doing this directly from X++.  I chose to create a C# class that references a ssh.net dll and then call that class from x++. Here is how I did it.

1. Create a new C# Class Library project in Visual Studio. I named mine 'CompanyToolbox' so I could add other helper classes to it in the future.
2. Add Project to AOT
3. Install the SSH.Net NuGet Package

4. Create the 'SFTPHelper' class, and the UploadFile method. 

5. Set the Deploy to Client and Deploy to Server Properties of the project.

6. Add Project to AOT & Deploy
7. Once you Deploy, you should see the 'CompanyToolbox' DLL in the Server and Client Bin folders.

8. Unfortunately, I could not get the referenced renci.sshnet.dll to be automatically deployed to the client and server bins, so I had to manually drop them in.  You can copy the Renci.sshnet.dll from this location -      'C:\Users\(yourUsername)\AppData\Local\Temp\2\Microsoft Dynamics AX\C Sharp Projects\CompanyToolbox\bin\Debug'.  Paste the dll into the both the client and server bin folders. 

9. Restart the AOS if hot swapping is not enabled.
10. Call the method from x++.   


      Done! 





No comments:

Post a Comment