Two dedicated ftp operations tasklets are provided in Summer Batch:
Summer.Batch.Extra.FtpSupport.FtpPutTasklet
: provides a basic ftp put operation support;
Summer.Batch.Extra.FtpSupport.FtpGetTasklet
: provides a basic ftp get operation support.
Both are using the System.Net.FtpWebRequest
ftp client.
Using the FtpPutTasklet
, you can put a given file on 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 use to connect to the ftp host;
Password : password for the above ftp user.
The following properties are optional (need to be set at initialization time, but a default value is provided):
Port : ftp host port (if non standard). Defaults to 21;
RemoteDirectory : path to ftp remote directory. Defaults to empty string, meaning that the defaut 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 here is a sample Unity configuration:
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 use to connect to the ftp host;
Password : password for the above ftp user;
FileNamePattern : a filename pattern, similar in form to what DirectoryInfo.GetFiles(string) supports to filter the files to be downloaded from the fpt remote directory;
LocalDirectory : path to local directory where downloaded files will be stored; The AutoCreateLocalDirectory boolean property controls
whether the local directory should be automatically created if non-existent (defaults to true); If AutoCreateLocalDirectory is set to false, and the 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 (need to be set at initialization time, but a default value is provided):
Port : ftp host port (if non standard). 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. The FileNamePattern property will be used to filter the files that need deletion.
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(); …