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

 

 

Advertisements

2 comments on “File Upload – FTP

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

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

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