You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Introduction

This is the third in a series of articles describing how to get started with using the the JADE Client via its Command Line Interface.

Articles in this series are:

  1. Getting Started and Downloading files
  2. Simple File Selection
  3. More Advanced File Selection
  4. Checking files for completeness
  5. Public / Private Key Authentication

File Selection - More Complex Examples

Polling a source directory for a minimum number of files

JADE can poll a source directory at regular intervals until it finds a file name match or until a specified length of time has elapsed. If it finds a file name match with one or more files it will then transfer the matching file(s) and then stop polling.

JADE can also delay transfer until a minimum number of file name matches has been found.

JADE will transfer all those files it has found at the end of the polling interval if the minimum number of matches has not been reached.

Example

In the example profile listed below the function of the four poll_* parameters should be self-explanatory but the following should be noted:

  • poll_interval - is specified in seconds (only integer values)

  • poll_timeout - is specified in minutes (only integer values)

  • poll_minfiles - optional - can only be used together with poll_timeout

[sftp_server_2_local_poll_minfiles]
;;
 operation                 = copy
 file_spec                 = ^test_[0-9]\.txt$
 poll_interval             = 20
 poll_timeout              = 1
 poll_minfiles             = 3
 poll_keep_connection      = true
;;
 source_host               = test.sos-berlin.com
 source_protocol           = sftp
 source_ssh_auth_method    = password
 source_port               = 22
 source_user               = demo
 source_password           = demo
 source_dir                = /
;;
 target_host               = localhost
 target_protocol           = local
 target_dir                = ${USERPROFILE}\jade_demo\a

Then call the profile by entering the following in the Windows command line:

jade.cmd -settings="%USERPROFILE%\jade_demo\jade_settings.ini" -profile="sftp_server_2_local_poll_minfiles"

Example behavior with poll_minfiles = 3  

  • JADE will transfer all the files found at the first polling - in this case the 5 test_*.txt files - as more than the minimum number of files has been found. Polling will then be stopped.
  • If no files were to be found then the JADE engine would throw an error as long as force_file = true has not been set.

Example behavior with poll_minfiles = 6

Change the poll_minfiles parameter in your settings file to 6, save the settings file and rerun the example.

  • JADE will find the five test_*.txt files when it polls but will not transfer the files as the minimum number of 6 has not been reached.
  • JADE will repeat polling until the time set in the poll_timeout parameter (in the example 1 minute) has expired.
  • Note that all the files that have been found will be transferred once the timeout has been reached.

File Transfer Examples

Renaming files

The following example combines two renaming possibilities:

  • Renaming files
  • Adding a date-stamp to file names

Example

The file name part(s) to be replaced is/are defined in the replacing parameter with round brackets () and the new part(s) in the replacement parameter, separated by semi-colons.

The example shows a two-part substitution:

  • test will be replaced with file_ and
  • '_' with the current date in the format specified.
[replace_local_datestamp]
;;
 operation                 = copy
 file_spec                 = ^test_[0-9]\.txt$
 replacing                 = ^(test)(_)[0-9]\.txt
 replacement               = file_;[date:yyyy-MM-dd]_
;;
 source_host               = localhost
 source_protocol           = local
 source_dir                = ${USERPROFILE}\jade_demo\a
;;
 target_host               = localhost
 target_protocol           = local
 target_dir                = ${USERPROFILE}\jade_demo\b

Call the 'replace_local_datestamp' profile by entering the following in the command line:

jade.cmd -settings="%USERPROFILE%\jade_demo\jade_settings.ini" -profile="replace_local_datestamp"

Behavior

The five test_*.txt files in the the a folder will be copied to the b folder and parts of their names will be replaced as described above.

File cumulation

JADE can cumulate the contents of individual files to a single target file:

  • Files matching the file_spec regular expression are cumulated together into a new file
  • The original files can be deleted if required
  • There is not a de-cumulate parameter available at the moment

Example

The example profile downloads the five text_*.txt files from our demo server and adds their contents successively to a cumulative file.

The cumulative file is then given the name specified in the cumulative_file_name parameter in the profile.

The text specified in the  cumulative_file_separator parameter is incorporated in the cumulative file between the contents of the individual files.

The order in which the files are added to the cumulative file is not fixed but depends on the order in which the files arrive on the local file system.

[sftp_server_2_local_cumulate]
;;
 operation                 = copy
 file_spec                 = ^test_.\.txt$
 cumulate_files            = true
 cumulative_file_name      = text-files.txt
 cumulative_file_separator = --- File: %{SourceFileName} ---
;;cumulative_file_delete   = true
;;
 source_host               = test.sos-berlin.com
 source_protocol           = sftp
 source_ssh_auth_method    = password
 source_port               = 22
 source_user               = demo
 source_password           = demo
 source_dir                = /
;;
 target_host               = localhost
 target_protocol           = local
 target_dir                = ${USERPROFILE}\jade_demo\a

Run the example using:

jade.cmd -settings="%USERPROFILE%\jade_demo\jade_settings.ini" -profile="sftp_server_2_local_cumulate"

Behavior

Opening the cumulative file text-files.txt in a text editor after transfer has been completed shows the order in which individual files were added to the cumulative file.

Note that this will not necessarily follow the order in which transfer of individual files was started.

File compression and decompression

JADE can compress individual files locally using a gzip-compatible compression. Compressed files can then be stored locally or forwarded to a further destination. JADE is not currently able to include a number of files in an unpackable container as is usually done with desktop zip archivers.

Example

The example profile will cause JADE to download the two PDF files on the remote host, compress them and then store them in the local directory a.

The files have the following sizes before compression:

  • lorem_ipsum_large.pdf - 115 KB
  • lorem_ipsum_medium.pdf - 32 KB
[sftp_server_2_local_compress]
;;
 operation                 = copy
 file_spec                 = ^.*\.pdf$
 compress_files            = true
;;
 source_host               = test.sos-berlin.com
 source_protocol           = sftp
 source_ssh_auth_method    = password
 source_port               = 22
 source_user               = demo
 source_password           = demo
 source_dir                = /large/
;;
 target_host               = localhost
 target_protocol           = local
 target_dir                = ${USERPROFILE}\jade_demo\a

Run the example using:

jade.cmd -settings="%USERPROFILE%\jade_demo\jade_settings.ini" -profile="sftp_server_2_local_compress"

Behavior

After transfer and compression the files are stored with the default suffix .gz. This suffix can be changed if required by setting a compressed_file_extension parameter.

The example files will be reduced in size to approximately 26 KB (lorem_ipsum_large.pdf) and 23 KB (lorem_ipsum_medium.pdf).

File decompression

The decompress_after_transfer parameter can be used to decompress files after transfer.

Alternatively, a program such as 7-Zip can be used to manually extract the original file from the archive.

  • No labels