Using the FTP Inbound Adapter
This page describes how to use the FTP inbound adapter (EnsLib.FTP.InboundAdapterOpens in a new tab).
Tip:
InterSystems IRIS® also provides specialized business service classes that use this adapter, and one of those might be suitable for your needs. If so, no programming would be needed. See “Connectivity Options” in Introducing Interoperability Productions.
Overall Behavior
The EnsLib.FTP.InboundAdapterOpens in a new tab enables InterSystems IRIS to receive files via the FTP protocol. The adapter receives FTP input from the configured location, reads the input, and sends the input as a stream to the associated business service. The business service, which you create and configure, uses this stream and communicates with the rest of the production.
If the FTP server expects an acknowledgment or response to its input, the business service is also responsible for formulating this response and relaying it back to the data source, via the EnsLib.FTP.InboundAdapterOpens in a new tab. The adapter does not evaluate or supplement the response, but relays it, if it is provided.
The following figure shows the overall flow of inbound messages (but not the responses):
In more detail:
-
Each time the adapter encounters input from its configured data source, it calls the internal ProcessInput() method of the business service class, passing the stream as an input argument.
-
The internal ProcessInput() method of the business service class executes. This method performs basic production tasks such as maintaining internal information as needed by all business services. You do not customize or override this method, which your business service class inherits.
-
The ProcessInput() method then calls your custom OnProcessInput() method, passing the stream object as input. The requirements for this method are described in Implementing the OnProcessInput() Method.
If the data source expects an acknowledgment or response of some kind, the OnProcessInput() method of the business service creates it. The inbound adapter simply relays this response back to the external data source.
The response message follows the same path, in reverse.
Example Business Service Class
The following code example shows a business service class that references the EnsLib.FTP.InboundAdapterOpens in a new tab.
Class EnsLib.FTP.PassthroughService Extends Ens.BusinessService
{
Parameter ADAPTER = "EnsLib.FTP.InboundAdapter";
/// Configuration item(s) to which to send file stream messages
Property TargetConfigNames As %String(MAXLEN = 1000);
Parameter SETTINGS = "TargetConfigNames";
/// Wrap the input stream object in a StreamContainer message object and send
/// it. If the adapter has a value for ArchivePath, send async; otherwise send
/// synchronously to ensure that we don't return to the Adapter and let it
/// delete the file before the target Config Item is finished processing it.
Method OnProcessInput(pInput As %Stream.Object,
pOutput As %RegisteredObject) As %Status
{
Set tSC=$$$OK, tSource=pInput.Attributes("Filename"),
tFileLocation=pInput.Attributes("FTPDir"),
pInput=##class(Ens.StreamContainer).%New(pInput)
Set tWorkArchive=(""'=..Adapter.ArchivePath)
For iTarget=1:1:$L(..TargetConfigNames, ",") {
Set tOneTarget=$ZStrip($P(..TargetConfigNames,",",iTarget),"<>W")
Continue:""=tOneTarget
$$$sysTRACE("Sending input Stream ...")
If tWorkArchive {
Set tSC1=..SendRequestAsync(tOneTarget,pInput)
Set:$$$ISERR(tSC1) tSC=$$$ADDSC(tSC,tSC1)
} Else {
#; If not archiving send Sync to avoid Adapter deleting file before
#; Operation gets it
Set tSC1=..SendRequestSync(tOneTarget,pInput)
Set:$$$ISERR(tSC1) tSC=$$$ADDSC(tSC,tSC1)
}
}
Quit tSC
}
}
Note that this example sets two variables to capture metadata about the incoming stream, pInput:
-
tSource captures the original file name, which is stored in the Filename subscript of the Attributes property of the incoming stream
-
tFileLocation captures the complete original file path, which is stored in the FTPDir subscript of the same property
Adding and Configuring the Business Service
To add your business service to a production, use the Management Portal to do the following:
-
Add an instance of your business service class to the production.
-
Configure the business service. For information on the settings, see Reference for Settings.
-
Enable the business service.
-
Run the production.