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);

Leave a Comment