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.


23 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=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPSessionOptions DotNet WinSCP.SessionOptions.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferOptions DotNet WinSCP.TransferOptions.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferResults DotNet WinSCP.TransferOperationResult.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      Directory Record File
      WinSCPTransferResumeSupport DotNet WinSCP.TransferResumeSupport.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPTransferResumeSupportState DotNet WinSCP.TransferResumeSupportState.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      MoveFileDotNet DotNet System.IO.File.’mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089′
      WinSCPProtocol DotNet WinSCP.Protocol.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPFtpSecure DotNet WinSCP.FtpSecure.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPRemoteInfoColl DotNet WinSCP.RemoteDirectoryInfo.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      WinSCPRemoteInfo DotNet WinSCP.RemoteFileInfo.’WinSCPnet, Version=, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf’
      FileManagement Codeunit File Management
      DirectoryCheck DotNet System.IO.Directory.’mscorlib, Version=, 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/ ‘;
        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?


  5. Hi,
    Really found this very useful. Many thanks.
    is there a way to use WinSCP without public key through nav.?? I can access the folder in GUI client without the public key, but when I try the same using code I’m getting an error like “A call to WinSCP.Session.Open failed with this message: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set.”
    Any idea.?

Leave a Reply

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

You are commenting using your 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