Tim Miller · Nov 11, 2019

Creating an FTP Report

Good morning all,

A question to see if anyone out there is already doing this.

We have built a custom BS based off of the EnsLib.FTP.InboundAdapter.  We have our processes wake up (using the Scheduler), grab the files in the directory, stay awake for a while, and then go back to sleep.

Each file goes through on its own message.  So we can trace each individual file and we know if it made it successfully or not.

What we would like to add is a status report email that creates a list of all the files sent in a "batch".  So if the BS wakes up and processes 44 files, then there is one email or report with those 44 files instead of 44 separate emails.

I was thinking of using a SQL query against the Ens.MessageHeader table but I was wondering if anyone had other suggestions.




1 0 1 182
Log in or sign up to continue


Hi Tim,

I know that is a old question, and I don't know if you have resolved your problem.

I have something like you are asking in a process. Maybe it could help you.

I created a persistent class with theses properties, also add a Query to retrieve info from a ProcessId:

Class FtpFileReport Extends %Persistent

/// ProcessId
Property ProcessId As %String;

/// Filename
Property FileName As %String;

/// Retrieve records of a ProcessId
Query GetRecordsByProcessId(pProcessId As %String) As %SQLQuery
    SELECT ProcessId, FileName
    FROM FtpFileReport
    WHERE ProcessId = :pProcessId


Then, when my process start to grabs the file, create a ProcessId, for example, using a combination of horolog and cryptotoken, to create an unique Id.

set pProcessId = "ID"_$PIECE($HOROLOG,",")_$PIECE($HOROLOG,",",*)_$SYSTEM.Encryption.GenCryptToken()

For each file grabbed, you save a record in your persistent class

set obj=##class(FtpFileReport).%New()

set obj.ProcessId = pProcessId    ;pProcessId is the variable with the Id created previously

set obj.FileName =  pFileName   ;if you are using retrieveFile method, it is the name the file that is grabbing

do obj.%Save()

Afterward, create a message to a BO that send the email with the ID of the process and create the message body based on ProcessId files:

Class SendEmail Extends Ens.BusinessOperation

Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";

Parameter INVOCATION = "Queue";

/// Send email of FTP Report
Method SendFtpReport(pRequest As Ens.StringRequest, Output pResponse As Ens.StringResponse) As %Status
    #dim myList As %Library.ListOfObjects

    set report  = ##class(FtpFileReport).%New()
    set myList = ##class(%Library.ListOfObjects).%New()
    set resultset = report.GetRecordsByProcessId(pRequest.StringValue)
    set data = ##class(%Stream.GlobalCharacter).%New()
    while resultset.%Next()
        set fileNum = $Increment(fileNum)
        do data.Write("<b>"_fileNum_":</b><p>"_resultset.%Get("FileName")_"</p><hr>")
        do myList.Insert(data)

    set msg = ##class(%Net.MailMessage).%New()
    set msg.IsHTML = 1
    do msg.TextData.WriteLine("<h1>FileReport</h1><br><h2>This is the FTP report: <h2><br><br>")    ; This is the body of the email

    for pos=1:1:myList.Size
        do msg.TextData.Write(myList.GetAt(pos).Read())

    set msg.To = ##class(%Library.ListOfObjects).%New()  ;Destinations address
    do msg.To.Insert("")
    set msg.Subject= "File report"
    do ..Adapter.SendMail(msg)

    set pResponse = ##Class(Ens.StringResponse).%New("Ok")
    quit $$$OK

XData MessageMap
  <MapItem MessageType="Ens.StringRequest">



I hope helps you.

Francisco Lopez