File Upload – SFTP

 

Hey Friends,

This post I dedicated in how to upload a file on SFTP from NAV. This normally happens when we are doing some sort of processing from a file which has to be processed needs to be downloaded from a SFTP and then eventually needs to be processed. SFTP is Secured File Transfer Protocol so it’s  a level more secured then FTP.

Below is the screenshot of the code that needs to be written.

This code is to move File to respective SFTP.

WinSCP is free DLL that you can find over internet and its very effective.

CHEERS

Advertisements

20 comments on “File Upload – SFTP

  1. Pingback: File Upload – SFTP - Microsoft Dynamics NAV Community

  2. Pingback: File Upload – SFTP - Dynamics NAV by RockWithNAV - Dynamics NAV Users - DUG

  3. Hi

    Im having problems to use the WinSPC library on NAV, I can find the type and the class on declaring variables, but thows an error when try to execute saying can create an instance of .NET object WinSpcnet…

    I’ve registered

    Any ideas?

  4. Great!!!. Sorry for delayed response, Was somehow busy with Christmas and New Year Celebrations 🙂

    Let me know for any more concerns.

    • Hi Raj,

      Sorry for late reply – Was busy in Projects.
      Do you just want variables or entire code. I can share all to you.
      Here are the variables

      Name DataType Subtype Length
      WinSCPSesh DotNet WinSCP.Session.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPSessionOptions DotNet WinSCP.SessionOptions.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferOptions DotNet WinSCP.TransferOptions.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferResults DotNet WinSCP.TransferOperationResult.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      Directory Record File
      WinSCPTransferResumeSupport DotNet WinSCP.TransferResumeSupport.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferResumeSupportState DotNet WinSCP.TransferResumeSupportState.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      MoveFileDotNet DotNet System.IO.File.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′
      WinSCPProtocol DotNet WinSCP.Protocol.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPFtpSecure DotNet WinSCP.FtpSecure.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPRemoteInfoColl DotNet WinSCP.RemoteDirectoryInfo.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPRemoteInfo DotNet WinSCP.RemoteFileInfo.’WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      FileManagement Codeunit File Management
      DirectoryCheck DotNet System.IO.Directory.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

      • Hello,

        Can you please share me information about the TEXT001.

        Because I am getting error while Authentication failed (WinSCPSesh.ExecutablePath) at this point.

    • Hi Llyod,

      Sorry for late reply was bit busy on my Projects – This code will do for all files available. Are you facing any Issue??
      This will execute for multiple files!!

      • Hi I managed to get this to work by specifying a mask of *.csv | archive/

        //uploading files
        transferOptions := transferOptions.TransferOptions;
        transferOptions.TransferMode := WinSCPTransferMode.Binary;
        transferOptions.FileMask := ‘*.csv | archive/ ‘;
        transferOptions.PreserveTimestamp(FALSE);
        transferResult := session.PutFiles(LocalDir,RemoteFTPDir,FALSE,transferOptions);

        //Downloading Files
        transferResult := session.GetFiles(DownloadFromPath,DownloadToPath,FALSE,transferOptions);

        My only issue now is that I cannot run via a NAS! In order to test from a Page I had to specify RunAsClient on all dotnet variables which worked fine. However I want to automate via a NAS. If I remove this the NAS still does not work despite the dlls existing on the server.

        Any ideas?

        Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s