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

File Upload – FTP

 

Hey Friends,

This post I dedicated in how to upload a file on FTP 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 FTP and then eventually needs to be processed.

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

This one is a very simple example, you can manipulate this as per your need. In the very next post I will come up on dealing with SFTP. This one will work only for FTP.

//RWN
ConnectionString := ‘ftp://your.ftp.address’;

SourceText := ‘Something that you want to write in the file’;

FTPRequest := FTPRequest.Create(ConnectionString);

FTPRequest.KeepAlive := TRUE;
FTPRequest.UseBinary := TRUE;
FTPRequest.Method := ‘STOR’;

FTPRequest.Credentials := NetworkCredential.NetworkCredential(‘UserID’,’Password’);

UTF8Encoding := UTF8Encoding.UTF8Encoding;

FTPRequest.ContentLength := UTF8Encoding.GetBytes(SourceText).Length;
RequestStream := FTPRequest.GetRequestStream;
RequestStream.Write(UTF8Encoding.GetBytes(SourceText),0,FTPRequest.ContentLength);
RequestStream.Close;

FTPResponse := FTPRequest.GetResponse;
MESSAGE(FTPResponse.StatusDescription);
//RWN

Variables

FTPRequest  DotNet System.Net.FtpWebRequest.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ FTPRequest DotNet System.Net.FtpWebRequest.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

FTPResponse DotNet System.Net.FtpWebResponse.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

NetworkCredential DotNet System.Net.NetworkCredential.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ WebRequestMethods DotNet System.Net.WebRequestMethods.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

UTF8Encoding DotNet System.Text.UTF8Encoding.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

RequestStream DotNet System.IO.Stream.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

ConnectionString Text

SourceText Text

CHEERS