Two dedicated FTP operations tasklets are provided in Summer Batch:
Summer.Batch.Extra.FtpSupport.FtpPutTasklet
: provides FTP put operation support;
Summer.Batch.Extra.FtpSupport.FtpGetTasklet
: provides FTP get operation support.
Both are using the System.Net.FtpWebRequest
FTP client.
Using FtpPutTasklet
you can put a given file into a FTP remote directory.
The following properties are mandatory (need to be set at initialization time):
FileName : path to the file that will be put on the FTP remote directory;
Host : FTP host (name or I.P. address);
Username : the user name to connect to FTP host;
Password : password for the above FTP user.
The following properties are optional (Default value is provided, however can set at initialization time):
Port : FTP host port. Defaults to 21;
RemoteDirectory : path to FTP remote directory. Defaults to empty string, meaning that the default remote directory is the FTP root directory.
Configuring the FtpPutTasklet
in the job XML file:
Example 7.8. FtpPutTasklet
usage in the job XML file
and sample Unity configuration is as below:
Example 7.9. FtpPutTasklet
Unity configuration
… /// <summary> /// Registers the artifacts required for step FtpPutStep. /// </summary> /// <param name="container">the unity container to use for registrations</param> private void RegisterFtpPutStep(IUnityContainer container) { container.StepScopeRegistration<ITasklet, FtpPutTasklet>("FtpPutBatchlet") .Property("Host").Value("myftp.mycompany.com") .Property("FileName").Resource("#{settings['FtpPutBatchlet.FILENAME_IN']}") .Property("Username").Value("anonymous") .Property("Password").Value("123soleil") .Register(); …
Using the FtpGetTasklet
, you can get a given set of files from a FTP remote directory.
The following properties are mandatory (need to be set at initialization time):
Host : FTP host (name or I.P. address);
Username : the user name to connect to the FTP host;
Password : password for FTP user;
FileNamePattern : a filename pattern, similar in form to what DirectoryInfo.GetFiles(string) supports to filter the files to be downloaded from the FTP remote directory;
LocalDirectory : path to local directory where downloaded files will be stored;
AutoCreateLocalDirectory : boolean flag to control whether the local directory should be automatically created if non-existent (defaults to true); If AutoCreateLocalDirectory is set to false and LocalDirectory does not exist, a
System.IO.DirectoryNotFoundException
will be thrown at run time.
RemoteDirectory : path to FTP remote directory to download files from;
The following properties are optional (Default value is provided, however can set at initialization time):
Port : FTP host port; Defaults to 21;
AutoCreateLocalDirectory : defaults to true; see LocalDirectory item above for the meaning of this flag;
DownloadFileAttempts : number of file download attempts before giving up; Defaults to 12;
RetryIntervalMilliseconds : Time in milliseconds to wait for a retry (after a failure); defaults to 300000;
DeleteLocalFiles : boolean flag (defaults to true) to indicate whether local existing files (from a prior download for example) will be deleted before attempting a fresh download. FileNamePattern property will be used to filter files to be deleted.
Configuring the FtpGetTasklet
in the job XML file:
Example 7.10. FtpGetTasklet
usage in the job XML file
and here is a sample Unity configuration :
Example 7.11. FtpGetTasklet
Unity configuration
… /// <summary> /// Registers the artifacts required for step FtpGetStep. /// </summary> /// <param name="container">the unity container to use for registrations</param> private void RegisterFtpGetStep(IUnityContainer container) { container.StepScopeRegistration<ITasklet, FtpGetTasklet>("FtpGetBatchlet") .Property("Host").Value("myftp.mycompany.com") .Property("FileNamePattern").Value("*.txt") .Property("Username").Value("anonymous") .Property("Password").Value("123soleil") .Property("LocalDirectory").Value("C:/temp/downloads") .Property("RemoteDirectory").Value("/my/remote/directory") .Register(); …