Package com.nt.udc.ei.transport
Class FtpEITransport
java.lang.Object
com.nt.udc.ndk.node.EITransport
com.nt.udc.ei.transport.FtpEITransport
- All Implemented Interfaces:
DataProviderIfc
,DCTransport
,FileDataProviderIfc
,Runnable
Used to retrieve files from an FTP server. This class serves
as an EI transport within the NDK framework and retrieves either
a single file or multiple files within a remote path periodically.
To use this class, you instantiate it with the IP address of the
machine from which you want to retrieve files (known as the FTP
server), the FTP username/password, and either a remote file path
and file suffix combination, or the path and name of a single
file. (There are two constructors available for you.) There is
also a constructor parameter which indicates whether you want to
use binary or ASCII transfer mode.
This class also relies on an object of type SynchronizedDirectory, which provides the synchronization capability for this transport class and any class which consumes (processes) the files that are retrieved via objects of this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
protected FtpSupportIntf
protected static final String
protected static final int
Fields inherited from class com.nt.udc.ndk.node.EITransport
dataReceiver, fdChecked, filedataReceiver, fileduplicateCheck, fileToProcess, inputCount, lockFile, movedFile, node, pollingInterval, processing, processingData, running
-
Constructor Summary
ConstructorsConstructorDescriptionFtpEITransport
(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary) This form of the constructor is used when you need to retrieve just a single file periodically.FtpEITransport
(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag) This form of the constructor is used when you need to retrieve just a single file periodically.FtpEITransport
(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag, String ftpType) This constructor is used when the ftpType needs to be specifiedFtpEITransport
(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType) This constructor is used when the ftpType needs to be specifiedFtpEITransport
(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary) This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.FtpEITransport
(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag) This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.FtpEITransport
(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag, String ftpType) This constructor is used when the ftpType needs to be specifiedFtpEITransport
(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType) This constructor is used when the ftpType needs to be specifiedFtpEITransport
(String ip, String l, String pw, EINode node) This form of the constructor establishes the minimum FTP parameters for this transport. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
This method actually creates the connection, retrieves the files and notifies the consumer of the files via the SynchronizedDirectory.protected boolean
This method actually creates the connection, retrieves a file and notifies the consumer of the file via the SynchronizedDirectory.void
enablePassiveFTP
(boolean passive) Enable the use of Passive FTP.Not used.getData()
Not used.boolean
Access flag for deleting remote files.boolean
Accesses the IP address of the FTP server.protected String
getLocalName
(String remoteFile) Accesses the local suffix.Retrieves the password for the FTP session.Accesses the name of the remote file to be retrieved.Accesses the path from which to retrieve file(s) on the FTP server.Accesses the remote suffix.boolean
Gets the flag for renaming remote filesprotected ArrayList
int
Accesses the time to wait before subsequent retrievals.Accesses the "common" local directory into which files are retrieved and from which files are processed.Retrieves the login name for the FTP session.boolean
Not used.boolean
This method is used to check if the transport is fully functional.void
run()
Workhorse of this class: Continuously retrieve the files and process them until it's time to shut down.void
Sets the FTP retrieval mode to ASCII Call this after constructing the transport, or ftpSession will be null and this method will have no effect.void
Sets the FTP retrieval mode to binary.void
setDeleteRemoteFiles
(boolean flag) Sets flag for deleting remote files once retrieved.void
setFlattenDirs
(boolean value) void
setLocalSuffix
(String suffix) Sets the suffix of files that need to be processed.void
setOverwriteExisting
(boolean flag) Sets flag that determines if files should be overwritten via FTP.void
setRemoteFile
(String filespec) Sets the name of the remote file to be retrieved.void
setRemotePath
(String path) Sets the path from which to retrieve file(s) on the FTP server.void
setRemoteSuffix
(String suffix) Sets the suffix of files to retrieve from the FTP server.void
setRenameRemoteSuffix
(boolean flag) Sets the flag for renaming Remote Filesvoid
setSleepTime
(int time) Sets the time to wait before subsequent retrievals.void
Establishes the "common" local directory into which files are retrieved and from which files are processed.void
setUseTimestampInLocalName
(boolean flag) Sets flag that determines if timestamp is used to form part of the local file name of a retrieved file.void
shutdown()
This method is used to provide a means of shutting down the transport in an orderly fashion.protected void
sleep
(int sleepSecs) Sleep for a given intervalMethods inherited from class com.nt.udc.ndk.node.EITransport
getCurrArchFile, getData, getDataReceiver, getDubCheckObj, getDupCheckFlag, getFileBulkData, getFileData, getFileDataReceiver, getFileList, getMovedFileStatus, getNode, getPollingInterval, getProcessedArchFile, handleRejectOfFile, incrementIn, incrementIn, isEndOfFile, isFileDataAvailable, isProcessing, isProcessingData, isStartOfFile, moveCurrentFileToBackUp, openInputFile, rejectFile, removeProcessedFile, setCountsSuspect, setDataReceiver, setFileDataReceiver, setFileToProcess, setMovedFileStatus, setNode, setPollingInterval, setProcessedArchFile, setProcessing, signalBatchCompletion, validOIMinorType
-
Field Details
-
ftpSession
-
FTP_TYPE_REGULAR
- See Also:
-
FTP_TYPE_SECURE
- See Also:
-
FTP_TYPE_PASSIVE
- See Also:
-
SFTP_PORT
protected static final int SFTP_PORT- See Also:
-
HOSTS_FILE
- See Also:
-
-
Constructor Details
-
FtpEITransport
This form of the constructor establishes the minimum FTP parameters for this transport. If you use this form you must manually set the required FTP parameters via the class accessors.- Parameters:
ip
- The IP address of the FTP serverl
- The username to use for loggin inpw
- The password for the given usernamenode
- The EI Node that is using this transport object
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary) This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.- Parameters:
ip
- The IP address of the FTP serverl
- The username to use for loggin inpw
- The password for the given usernamest
- The number of milliseconds to wait between successive retrievalsflag
- Determines whether to delete the remote files once they are retrievedrp
- The path or directory on the FTP server that contains the filessuffix
- Specifies the suffix for the files that will be retrievedlSuffix
- Specifies the suffix for the files on the local machine after they're retrieveddir
- The local directory into which files will be placednode
- The EI Node that is using this transport objectbinary
- Determines if files should be retrieved in binary mode (false = ASCII mode)
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType) This constructor is used when the ftpType needs to be specified- Parameters:
ftpType
- Determines the type of FTP to use
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary) This form of the constructor is used when you need to retrieve just a single file periodically.- Parameters:
ip
- The IP address of the FTP serverl
- The username to use for logging inpw
- The password for the given usernamest
- The number of milliseconds to wait between successive retrievalsflag
- Determines whether to delete the remote files once they are retrievedfile
- Specifies the file that will be retrieved (including path)dir
- The local directory into which files will be placednode
- The EI Node that is using this transport objectbinary
- Determines if files should be retrieved in binary mode (or ASCII mode)
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType) This constructor is used when the ftpType needs to be specified- Parameters:
ftpType
- Determines the type of FTP to use
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag) This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.- Parameters:
ip
- The IP address of the FTP serverl
- The username to use for loggin inpw
- The password for the given usernamest
- The number of milliseconds to wait between successive retrievalsflag
- Determines whether to delete the remote files once they are retrievedrp
- The path or directory on the FTP server that contains the filessuffix
- Specifies the suffix for the files that will be retrievedlSuffix
- Specifies the suffix for the files on the local machine after they're retrieveddir
- The local directory into which files will be placednode
- The EI Node that is using this transport objectbinary
- Determines if files should be retrieved in binary mode (false = ASCII mode)rRenameflag
- flag for Renaming Remote File
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag, String ftpType) This constructor is used when the ftpType needs to be specified- Parameters:
ftpType
- Determines the type of FTP to use
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag) This form of the constructor is used when you need to retrieve just a single file periodically.- Parameters:
ip
- The IP address of the FTP serverl
- The username to use for logging inpw
- The password for the given usernamest
- The number of milliseconds to wait between successive retrievalsflag
- Determines whether to delete the remote files once they are retrievedfile
- Specifies the file that will be retrieved (including path)dir
- The local directory into which files will be placednode
- The EI Node that is using this transport objectbinary
- Determines if files should be retrieved in binary mode (or ASCII mode)rRenameFlag
- flag for Renaming Remote File
-
FtpEITransport
public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag, String ftpType) This constructor is used when the ftpType needs to be specified- Parameters:
ftpType
- Determines the type of FTP to use
-
-
Method Details
-
run
public void run()Workhorse of this class: Continuously retrieve the files and process them until it's time to shut down. Note the use of the "wasInterrupted" flag to help keep track of when this thread gets interrupted. If the thread is in the middle of the connectAndGet() method, we must let it finish before shutting down the thread.- Specified by:
run
in interfaceRunnable
- Specified by:
run
in classEITransport
-
connectAndGetFiles
protected boolean connectAndGetFiles()This method actually creates the connection, retrieves the files and notifies the consumer of the files via the SynchronizedDirectory. This method is used whenever the instance variableremoteFile
is null, which indicates we need to retrieve multiple files at a time.- Returns:
- true, if successful - false, if not
-
connectAndGetSingleFile
protected boolean connectAndGetSingleFile()This method actually creates the connection, retrieves a file and notifies the consumer of the file via the SynchronizedDirectory. This method is used whenever the instance variableremoteFile
is not null, which indicates we need to retrieve just a single file.- Returns:
- true, if successful - false, if not
-
sleep
Sleep for a given interval- Throws:
InterruptedException
-
shutdown
public void shutdown()Description copied from class:EITransport
This method is used to provide a means of shutting down the transport in an orderly fashion.- Specified by:
shutdown
in interfaceDCTransport
- Specified by:
shutdown
in classEITransport
-
getRetrivalList
- Throws:
IOException
-
getData
Not used.- Specified by:
getData
in interfaceDataProviderIfc
- Specified by:
getData
in classEITransport
- Returns:
- DCFieldContainer.
-
getBulkData
Not used.- Specified by:
getBulkData
in interfaceDataProviderIfc
- Specified by:
getBulkData
in classEITransport
- Returns:
- DCFieldContainer object array, containing the data that is for processing
-
isDataAvailable
public boolean isDataAvailable()Not used.- Specified by:
isDataAvailable
in interfaceDataProviderIfc
- Specified by:
isDataAvailable
in classEITransport
- Returns:
true
, if data is available
-
setUseTimestampInLocalName
public void setUseTimestampInLocalName(boolean flag) Sets flag that determines if timestamp is used to form part of the local file name of a retrieved file. -
setOverwriteExisting
public void setOverwriteExisting(boolean flag) Sets flag that determines if files should be overwritten via FTP. -
setBinaryMode
public void setBinaryMode()Sets the FTP retrieval mode to binary. Call this after constructing the transport, or ftpSession will be null and this method will have no effect. -
setASCIIMode
public void setASCIIMode()Sets the FTP retrieval mode to ASCII Call this after constructing the transport, or ftpSession will be null and this method will have no effect. -
setRemotePath
Sets the path from which to retrieve file(s) on the FTP server. Use this when you need to retrieve multiple files at a time.- Parameters:
path
- remote path
-
getRemotePath
Accesses the path from which to retrieve file(s) on the FTP server.- Returns:
- remote path
-
setLocalSuffix
Sets the suffix of files that need to be processed. This determines the suffix of the files once they are retrieved via FTP.- Parameters:
suffix
- local suffix
-
getLocalSuffix
Accesses the local suffix.- Returns:
- local suffix
-
setRemoteSuffix
Sets the suffix of files to retrieve from the FTP server. Use this when you need to retrieve multiple files at a time.- Parameters:
suffix
- remote suffix
-
getFlattenDirs
public boolean getFlattenDirs() -
setFlattenDirs
public void setFlattenDirs(boolean value) -
getRemoteSuffix
Accesses the remote suffix.- Returns:
- remote suffix
-
setSleepTime
public void setSleepTime(int time) Sets the time to wait before subsequent retrievals.- Parameters:
time
- number of seconds to wait
-
getSleepTime
public int getSleepTime()Accesses the time to wait before subsequent retrievals.- Returns:
- number of seconds to wait
-
setSynchronizedDirectory
Establishes the "common" local directory into which files are retrieved and from which files are processed.- Parameters:
dir
- encapsulation of the local directory
-
getSynchronizedDirectory
Accesses the "common" local directory into which files are retrieved and from which files are processed.- Returns:
- encapsulation of the local directory
-
setDeleteRemoteFiles
public void setDeleteRemoteFiles(boolean flag) Sets flag for deleting remote files once retrieved.- Parameters:
flag
- true = delete remote files
-
getDeleteRemoteFiles
public boolean getDeleteRemoteFiles()Access flag for deleting remote files.- Returns:
- true = delete remote files
-
setRemoteFile
Sets the name of the remote file to be retrieved. Must include the full path, if needed. Use this when you want to retrieve just a single file.- Parameters:
filespec
- remote path and filename
-
getRemoteFile
Accesses the name of the remote file to be retrieved.- Returns:
- remote path and filename (can be null)
-
setRenameRemoteSuffix
public void setRenameRemoteSuffix(boolean flag) Sets the flag for renaming Remote Files- Parameters:
flag
- true will set it
-
getRenameRemoteSuffix
public boolean getRenameRemoteSuffix()Gets the flag for renaming remote files- Returns:
- true if we want to rename remote files
-
getUsername
Retrieves the login name for the FTP session.- Returns:
- login name (can be null)
- Throws:
NullPointerException
- if ftpSession hasn't been established
-
getPassword
Retrieves the password for the FTP session.- Returns:
- password (can be null)
- Throws:
NullPointerException
- if ftpSession hasn't been established
-
getIPAddress
Accesses the IP address of the FTP server.- Returns:
- IP address (can be null)
- Throws:
NullPointerException
- if ftpSession hasn't been established
-
enablePassiveFTP
public void enablePassiveFTP(boolean passive) Enable the use of Passive FTP.- Parameters:
passive
-true
is Passive FTP is desired.
-
getLocalName
-
isHealthy
public boolean isHealthy()This method is used to check if the transport is fully functional.- Specified by:
isHealthy
in interfaceDCTransport
- Overrides:
isHealthy
in classEITransport
- Returns:
- true if the transport is healthy, false otherwise
-