Skip to main content

EnsLib.FTP.OutboundAdapter

class EnsLib.FTP.OutboundAdapter extends Ens.OutboundAdapter, EnsLib.FTP.Common, EnsLib.File.Common

Property Inventory

Method Inventory

Parameters

parameter SETTINGS = RegistryID:Basic:selector?context={Ens.ServiceRegistry.External.ContextSearch/Services?Protocols_1=FTP},Overwrite,SFTPAppendMode:SFTP,SemaphoreSpec,SemaphoreMissThreshold,-UseRegex;
These properties can be configured or set by the associated Business Operation

Properties

property Charset as %String [ InitialExpression = "Binary" ];
FTP Only - Use the named Character encoding to translate characters from the file.
A * prepended to any of the charset names will cause a binary FTP transfer with the resulting data then translated using the specified encoding.
Note that Binary should be chosen for binary files and other cases when special characters such as line terminators must be preserved.
Other settings may be useful when transferring text documents via FTP.

Choices include:
Binary - binary transfer
Ascii - Ascii mode FTP transfer but no character encoding translation
Native - the default character encoding of the installed locale of the InterSystems IRIS server
latin1 - the ISO Latin1 8-bit encoding
ISO-8859-1 - the ISO Latin1 8-bit encoding
UTF-8 - the Unicode 8-bit encoding
Unicode - the Unicode 16-bit encoding (Little-Endian)
UnicodeBig - the Unicode 16-bit encoding (Big-Endian)
@<ttable> - <ttable> means a raw InterSystems character translation table name. A prefix of '@' means to use the named table.

Property methods: CharsetDisplayToLogical(), CharsetGet(), CharsetIsValid(), CharsetLogicalToDisplay(), CharsetLogicalToOdbc(), CharsetNormalize()
property FilePath as %String (MAXLEN = 1000) [ Required ];
Directory on the FTP server in which to effect FTP operations.
Property methods: FilePathDisplayToLogical(), FilePathGet(), FilePathIsValid(), FilePathLogicalToDisplay(), FilePathLogicalToOdbc(), FilePathNormalize()
property Overwrite as %Boolean [ InitialExpression = 1 ];
Overwrite output file if it exists instead of appending
Property methods: OverwriteDisplayToLogical(), OverwriteGet(), OverwriteIsValid(), OverwriteLogicalToDisplay(), OverwriteNormalize(), OverwriteSet()
property SFTPAppendMode as %String (VALUELIST = ",Client,Server") [ InitialExpression = "Client" ];
If the protocol is SFTP and Overwrite=false then you should configure SFTP Append Mode also.

If the SFTP server supports appending then you should select 'Server' append mode. Some SFTP servers do not support appending. When connecting to such a server you should select 'Client' append mode.
Click here to test server side appendOpens in a new tab

In 'Client' mode the FTP adapter will retrieve the remote file (if it exists) from the server, append the new data locally, and then put the combined data back to the SFTP server.

There is a chance that some other process will remove the file from the server or modify the file on the server before the adapter puts the combined data back to the server. In this case the changes made by the other process could be lost.

The logic the SFTP adapter uses for local appending is:

  1. Check if the remote file exists
  2. If it exists it renames by adding .ToBeAppendedTo to the end of the name
  3. If it does not exist it looks for a prior name ending .ToBeAppendedTo
  4. If either of these existing files are found it is downloaded and the new data appended
  5. The combined file is put back and the prior file ending with .ToBeAppendedTo is removed
  6. If there is a network failure before putting the combined file on the server the adapter will use the .ToBeAppendedTo file on the next connection
Since the file being appended to might be locked by the SFTP server you should also consider configuring ReplyCodeActions so that the Operation retries upon error, e.g. E=R or E*Error.

Property methods: SFTPAppendModeDisplayToLogical(), SFTPAppendModeGet(), SFTPAppendModeIsValid(), SFTPAppendModeLogicalToDisplay(), SFTPAppendModeLogicalToOdbc(), SFTPAppendModeNormalize(), SFTPAppendModeSet()
property SemaphoreMissThreshold as %Integer [ InitialExpression = 5 ];
The number of times that we warn about no semaphore spec being met despite SemaphoreSpec being defined before we stop warning.
Property methods: SemaphoreMissThresholdDisplayToLogical(), SemaphoreMissThresholdGet(), SemaphoreMissThresholdIsValid(), SemaphoreMissThresholdLogicalToDisplay(), SemaphoreMissThresholdNormalize(), SemaphoreMissThresholdSet()
property SemaphoreSpec as %String (MAXLEN = 400);

Allows you to indicate that the data file or files are complete and ready to be read by creating an associated second file in the same directory that is used as a semaphore.

If the Semaphore Specification is an empty string, the adapter will not create a semaphore file.

SYNTAX: Semaphore Specification can be an empty string or can be a series of pairs, each of which associates a data filename pattern with a semaphore filename pattern. The pairs are separated by semicolons:

DataFileSpec=SemaphoreFileSpec;DataFileSpec=SemaphoreFileSpec;...

DataFileSpec is either a plain filename or a filename specification that includes the * wildcard (which matches any character). SemaphorePattern directly or indirectly specifies the name of the associated semaphore file; it can be either of the following:

  • A plain filename (such as SemaphoreFile.SEM). In this case, when the system finds a file that matches DataFileSpec, the system looks for a file with that exact name.
  • A string of the form *.extension such as *.sem. In this case, when the system finds a file that matches DataFileSpec, the system looks for a file with the same name, but with the sem extension instead. For example, if the filename ABCDEF.txt matches DataFileSpec, the system looks for a semaphore file named ABCDEF.sem. When looking for a semaphore file based on a data filename, the system looks only at the part of the data filename before the first period. For example, if the filename test.txt.data.zip.tar matches DataFileSpec, if the semaphore filename pattern is *.sem the system looks for a semaphore file named test.sem
Additional Notes:
  • The semaphore file associated with a given data file (or multiple data files) will be put in the same directory as those files.
  • DataFileSpec and SemaphoreFileSpec do not include the directory name.
  • DataFileSpec is always case-sensitive.
  • SemaphoreFileSpec is case-sensitive if the operating system is case-sensitive and is not case-sensitive otherwise. Thus, you should be aware of the details of the system that you are writing to.
  • The pairs are processed left-to-right, and the first matching pair is used; see below. Consequently, if you are including multiple specifications that can match the same file, you should specify the more specific specification before the more general ones.
  • Trailing or leading whitespace is removed, but not whitespace within the string. In other words, *.txt=*.sem;*.md=*.mdsem is not the same as *.txt=*.sem; *.md=*.mdsem

FILENAMES THAT DO NOT MATCH A PATTERN: If a Semaphore Specification is specified and a given data file does not match any of the patterns, then no semaphore file will be created. If downstream systems are expecting a semaphore file, this may cause them to not properly handle the file. If this is undesirable, specify a final pair that will match any file. For example, consider this Semaphore Specification:

*.DAT=*.SEM;*.DOC=*.READY;*=SEM.LAST

The SEM.LAST is the semaphore file for all files that do not end with .DAT or .DOC.

HOW THE ADAPTER USES SEMAPHORE SPECIFICATION: When a file is going to be put onto a server, the adapter will check the filename to see if there is a match in the Semaphore Specification. If there is, it will put the file onto the server and then put a semaphore file onto the server, with a filename that matches the appropriate Semaphore Specification. If there is no match, the adapter will not create a semaphore file. If this happens, we will log a warning the first 5 times. This number can be tuned by changing the Semaphore Miss Threshold property.

Property methods: SemaphoreSpecDisplayToLogical(), SemaphoreSpecGet(), SemaphoreSpecIsValid(), SemaphoreSpecLogicalToDisplay(), SemaphoreSpecLogicalToOdbc(), SemaphoreSpecNormalize(), SemaphoreSpecSet()

Methods

method CreateDirectory(dirname As %String, dirpath As %String = "", SFTPFilemode As %String = "0700", ByRef output) as %Status
Create a directory on an FTP server.
dirname is the name of the directory to create
dirpath is the path to the directory that we intend to create. If not supplied, path to the current directory is used.
SFTPFilemode is the file mode of the directory. This is only applied if the protocol is SFTP.
ByRef output FTP will return information about the name of the directory created in case there is some discrepancy. If an output variable is supplied, that return information will be stored within it.
Returns a status effect indicating whether the operation succeeded or failed.
method CreateFilename(pFilename As %String, pSpec As %String, pIsVMS As %Boolean, pDirectory As %String, pLocal As %Boolean) as %String
Passthrough method for the use of BatchStandardOperation classes. Non-trivial parallel version is defined in File adapter
method Delete(pFilename As %String) as %Status
Delete a named file from an FTP server. Server,Username,Password, and FilePath are configured as Settings for this Adapter. Returns a status value indicating the success of the FTP operation.
method GetStream(pFilename As %String, ByRef pStream As %Stream.Object = $$$NULLOREF) as %Status
Retrieve a named file from an FTP server and return it as a stream. Server,Username,Password,FilePath and Transfer mode (Charset) are configured as Settings for this Adapter. Returns a status value indicating the success of the FTP operation. If the caller provides a stream, it must be the appropriate type of stream for the transfer (Ascii, Binary). This method will create the stream if none is provided.
method NameList(Output pFileList As %ListOfDataTypes) as %Status
Get a list of files on an FTP server. Server,Username,Password, and FilePath are configured as Settings for this Adapter. The filenames are returned in a %ListOfDataTypes object. Returns a status value indicating the success of the FTP operation.
method PutStream(pFilename As %String, pStream As %Stream.Object) as %Status
Store a Stream to an FTP server as a named file. Server,Username,Password,FilePath and Transfer mode (Charset) are configured as Settings for this Adapter. Returns a status value indicating the success of the FTP operation.
method Rename(pFilename As %String, pNewFilename As %String, pNewPath As %String = "") as %Status
Rename a file on an FTP server. Server,Username,Password, and FilePath are configured as Settings for this Adapter. Returns a status value indicating the success of the FTP operation.

Inherited Members

Inherited Properties

Inherited Methods

FeedbackOpens in a new tab