FtpCopy

Group

Time-driven Custom Classes

Class Name

com.ebd.hub.datawizard.util.FtpCopy

Function

This class collects mass data via FTP and stores it locally, or on another FTP server. Alternatively, the files can be collected from a network drive or local directory.

Configuration File

sample_ftp_copy.xml

Description

This class collects mass data via FTP and stores it locally or on another FTP server. Alternatively, the files can be collected from a network drive or local directory (see notes for parameter channel of element account).

1. Element <account>:

Superordinate element. General settings for the copying. Attributes of the element:

host

The address of the FTP server. Delete this attribute, if the copying targets a network drive or local directory.

port

The port of the FTP server.

delete_files

If true, the copied files will be deleted.

source_dir

The source directory (mandatory). Even if the option delete_dir=true is set, this directory will not be deleted.

destination_dir

The target directory (mandatory). Even if the option delete_dir=true is set, this directory will not be deleted.

mode

active or passive. FTP transfer mode.

pattern

The file pattern of the files to be copied.

force_uppercase

If true, the file names in the target directory will be written in uppercase.

force_lowercase

If true, the file names in the target directory will be written in lowercase.

extract_zip

If true, ZIP files will be extracted in the copying process.

destination_host

Address of the target FTP server, if the copying destination is an FTP server.

destination_port

Port of the target FTP server, if the copying destination is an FTP server.

verbose

Attention: Applies to FTP and SFTP. If true, debug messages are displayed in the console. If the Integration Server runs on a Windows system as a service, the messages will be forwarded to the file logs/wrapper.log. If the integration server runs in the background on a Unix/Linux system, the messages will be forwarded to the file hub.txt.

delete_dir

If true, the copied directory will be deleted as well. Only works if the directory is empty, especially with local directories.

delete_target_dir

If true, the target directory (if it exists) is attempted to be deleted before copying it. This is only possible if the directory is an FTP directory and does not apply to the root directory.

binary

If true, the binary mode is used for the transfer.

sftp

true, if the server from which the data is sent is an SFTP server. Default: false.

destination_sftp

true, if the server to which the data is sent is an SFTP server. Default: false.

channel

ID of the channel from the Partner Administration. The user, password and the encryption are taken from the SSH or FTP channel from the Partner Administration (Local ID).

Attention: The parameter must not be used when fetching from a network drive or local directory.

destination_channel

ID of the destination channel from the Partner Administration. The user, password and the encryption are taken from the SSH or FTP channel from the Partner Administration (Remote ID).

2. Element <exclude_dir>, or optionally <include_dir>:

With <exclude_dir> you are able to define directories, which should be excluded from the transfer. Optionally, you can include directories with <include_dir>. Attributes of the two elements:

delete

true or false. Defines if the directory should be deleted.

3. Element <exclude_file>:

With <exclude_file> you can define files, which should be excluded from the transfer. Attributes of the element:

delete

true or false. Defines if the file should be deleted.

4. Element <replace>:

With this element, you can specify replacements in file names. This replacement does not work on directory names. Attributes of the element:

old_value

Characters to be replaced.

new_value

Replacement characters .

Example

sample_ftp_copy.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<!-- force_lowercase="true" forces the destination file name to be written in lower case; force_uppercase="true" for upper case -->
<account host="localhost" port="21" user="ftp" passwd="ftp" delete_files="false" source_dir="/" destination_dir="archiv" mode="passive" pattern="*" force_uppercase="false" force_lowercase="true" extract_zip = "true" destination_host="localhost" destination_port="21" destination_user="lobster" destination_passwd="secret" verbose="false" delete_dir="true" delete_target_dir="true" binary="true">
<!-- do not copy folders with the following names -->
<exclude_dir>archiv</exclude_dir>
<!-- here are replacements instructions -->
<replace old_value="ä" new_value="ae"/>
<!-- here is an exclude list of file pattern and whether to delete it or not -->
<exclude_file delete="true">~*</exclude_file> <!-- do not copy ~files and remove them locally -->
<exclude_file delete="false">*.tmp</exclude_file> <!-- do not copy *.tmp files and do not delete them locally -->
<!-- <include_dir>invoices</include_dir> -->
<!-- <include_dir>orders</include_dir> -->
</account>
</config>

Example since version 3.5.0 or when using patch_ftp_copy_with_channel.zip

sample_ftp_copy_3.5.0_patch.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<!-- force_lowercase="true" forces the destination file name to be written in lower case; force_uppercase="true" for upper case -->
<account host="localhost" port="22" channel="1443778549792012" sftp="true" delete_files="false" source_dir="/" destination_dir="archiv" pattern="*"
force_uppercase="false" force_lowercase="true" extract_zip = "true" verbose="false" delete_dir="true" binary="true">
<!-- do not copy folders with the following names -->
<exclude_dir>archiv</exclude_dir>
<!-- here are replacements instructions -->
<replace old_value="ä" new_value="ae"/>
<!-- here is an exclude list of file pattern and whether to delete it or not -->
<exclude_file delete="true">~*</exclude_file>
<!-- do not copy ~files and remove them locally -->
<exclude_file delete="false">*.tmp</exclude_file>
<!-- do not copy *.tmp files and do not delete them locally -->
<!-- <include_dir>invoices</include_dir> -->
<!-- <include_dir>orders</include_dir> -->
</account>
</config>

Output

The output is a CSV file with 8859_1 encoding. For each <account> element, Lobster_data will create a record. Following is an example of the output format.

HOST;localhost;a_user;/
OK;/fäle1.txt;/tmp/ftp/faele1.txt
OK;/dir1/file2.txt;/tmp/ftp/dir1/file2.txt
ERR;/file3.txt;some error messages
OK;/file_4.txt;/tmp/ftp/file_4.txt

Each record starts with a HOST line, which includes the host name, username and the source directory. This line is followed by n lines, starting with OK or ERR, depending on success or failure of the transfer and followed by the file name. The OK line also includes the source file name and the destination file name. The ERR line includes the file name and the error message.