Microsoft Dynamics NAV: Delete Remote FTP Files using dotNET Interop

In many data exchanges it is desired that a file be removed from the remote FTP server once it has been downloaded.  Building on the previous posts (List, Upload, Download) that extend FTP within Microsoft Dynamics NAV via dotNET Interop, the code listed below demonstrates how to remove a file via FTP. 

The local variables are declared as:

Name	DataType	Subtype
FtpWebRequest	DotNet	System.Net.FtpWebRequest.'System'
FtpWebResponse	DotNet	System.Net.FtpWebResponse.'System'
NetworkCredential	DotNet	System.Net.NetworkCredential.'System'

The function is declared as:

DeleteFile(siteaddress : Text[250];username : Text[80];password : Text[80];filename : Text[250])

FtpWebRequest := FtpWebRequest.Create(siteaddress + '/' + filename);
FtpWebRequest.Credentials := NetworkCredential.NetworkCredential(username, password);

FtpWebRequest.Method := 'DELE';
FtpWebRequest.KeepAlive := TRUE;
FtpWebRequest.UseBinary := TRUE;
//FtpWebRequest.UsePassive := FALSE;

FtpWebResponse := FtpWebRequest.GetResponse;

  MESSAGE('%1 %2', FtpWebResponse.StatusCode, FtpWebResponse.StatusDescription);

Add comment

Reading Stuff

Information in this document subject to change without notice.
All Software source code published is for demonstration and knowledge sharing purposes only. The Code is supplied "as is" without warranty as to result, performance or merchantability. Use at your own risk.
The opinions expressed herein are the opinions of the author and do not reflect those of any other entity.