View Source

{section}
{column}

{warning}This version must be installed on [Petals ESB 5.3.0|petalsesb530:Petals ESB 5.3.0]+{warning}

h1. Feature

The SFTP component is a Binding Component which supports SFTP commands.

This component provide a set of 5 operations:

* *put:* Write the received JBI messages in a file with a specified name.
* *mput:* Write the JBI message attachments it receives into files.
* *get:* Retrieve *Xml* file corresponding to a pattern, from a folder. Return it as message payload.
* *getAsAttachment:* Retrieve the first file corresponding to a pattern, from a folder. Return it as message's attachment.(XOP standard)
* *mGet:* Retrieve files corresponding to a pattern, from a folder. Return them as message's attachment.
* *del:* Delete one file.
* *dir:* List the content of a folder.

These operations are described in an embedded WSDL.

{info}All attachment are processed by using XOP rules (XML-binary Optimized Packaging : [http://www.w3.org/TR/xop10/]).{info}

{column}
{column:width=25%}
{panel:title=Table of contents}{toc:outline=true}{panel}
{panel:title=Contributors}{contributors:order=name|mode=list|showAnonymous=true|showCount=true|showLastTime=true}{panel}
{column}
{section}

h1. Exposing a FTP connection as a service

The component is able to expose an external service in the JBI environment to send SFTP commands on an SFTP server (*Service-unit mode*).

h2. Usage

The operations of the service exposed are explained here after:
* an operation need to be call explicitly in the form : \{service-namespace}operation (example: \{http://petals.ow2.org/components/sftp/version-1}put)
* all operations support wild card character.

h3. Put Operation

When the put operation is set on the incoming IN message, the component write the XML message to the SFTP server.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:put xmlns:ver="http://petals.ow2.org/components/sftp/version-1">
<ver:body>xml body</ver:body>
<ver:filename>file name on the server</ver:filename>
</ver:put>
{code}

The service does not return a message.

The service might return an error when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: *InOnly*.

{tip}The operation '{{put}}' of the generic service supports the automatic creation of the remote directory if it does not exist. Just set the parameter '{{create-folder}}' available in the section '{{connection}}' to '{{true}}'. See [connection parameters|#connection-parameters].{tip}

h3. MPut Operation

When the mput operation is set on the incoming IN message, the component write the attachments on the SFTP server.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:mput xmlns:ver="http://petals.ow2.org/components/sftp/version-1">
<ver:attachments>
<ver:filename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test1.xml"/></ver:filename>
<ver:filename name="my-file.txt"><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test2.xml"/></ver:filename>
</ver:attachments>
</ver:mput>
{code}

The file names used to store files on SFTP server is defined by the attribute '{{name}}'. If this attribute is missing or empty, the file name will be set to the attachment identifier extracted from '{{xop:Include#href}}'.

The service does not return a message.

The service might return an error when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: *InOnly*.

{tip}The operation '{{mput}}' of the generic service supports the automatic creation of the remote directory if it does not exist. Just set the parameter '{{create-folder}}' available in the section '{{connection}}' to '{{true}}'. See [connection parameters|#connection-parameters].{tip}

h3. Get Operation

When the get operation is set on the incoming IN message, the component retrieve ONE file from the SFTP server and return it as an XML message content.

The name of the file to retrieve is set in the XML IN content of the message.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:get xmlns:ver="http://petals.ow2.org/components/sftp/version-1">
<ver:filename>file name to retrieve</ver:filename>
</ver:get>
{code}

The OUT message returned to the consumer is the content of the XML file.

The service might return a Fault when an element in the request is missing or if the SFTP connection failed.

The available exchange patterns is: *InOut*.

{info}Only xml file could be processed otherwise an error will be raised.{info}

h3. GetAsAttachment Operation

When the get operation is set on the incoming IN message, the component retrieve ONE file from the SFTP server and return it as an attachment.

The name of the file to retrieve is set in the XML IN content of the message.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:getAsAttachment xmlns:ver="http://petals.ow2.org/components/sftp/version-1">
<ver:filename>file name to retrieve</ver:filename>
</ver:getAsAttachment>
{code}

The OUT message returned to the consumer contains files, as attachments, and an XML message report:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<tns:getAsAttachmentResponse xmlns:tns="http://petals.ow2.org/components/sftp/version-1">
<tns:attachment>
<tns:filename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test1.xml"/></tns:filename>
<tns:filename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test2.xml"/></tns:filename>
</tns:attachment>
</tns:getAsAttachmentResponse>
{code}

The service might return a Fault when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: *InOut*.

h3. MGet Operation

When the mget operation is set on the incoming IN message, the component retrieves files from the SFTP server, according to the file names (or filters) set in the XML request.

There is no recursivity, sub folders are ignored.

Each file is set in the OUT message as an attachment. The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:mget xmlns:ver="http://petals.ow2.org/components/sftp/version-1">
<!--1 or more repetitions:-->
<ver:filename>*.xml</ver:filename>
<ver:filename>myFile.txt</ver:filename>
</ver:mget>
{code}

The OUT message returned to the consumer contains files, as attachments, and an XML message report:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<tns:mgetResponse xmlns:tns="http://petals.ow2.org/components/sftp/version-1">
<tns:attachments>
<tns:filename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test1.xml"/></tns:filename>
<tns:filename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test2.xml"/></tns:filename>
</tns:attachments>
</tns:mgetResponse>
{code}

The service might return a Fault when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: *InOut*.

h3. Dir Operation

When the dir operation is set on the incoming IN message, the component returns the file names listed from the SFTP
server.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<ver:dir xmlns:ver="http://petals.ow2.org/components/sftp/version-1 />
{code}

The OUT message returned to the consumer is defined as follow:
{code:lang=xml}
<tns:dirResponse xmlns:tns="http://petals.ow2.org/components/sftp/version-1">
<!--Zero or more repetitions:-->
<tns:filename>file1.txt</tns:filename>
<tns:filename>linux.jpg</tns:filename>
</tns:dirResponse>
{code}

The service might return a Fault when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: *InOut*.

h3. Del Operation

When the del operation is set on the incoming IN message, the component delete the remote file.

The IN message looks like:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?><ver:del xmlns:ver="http://petals.ow2.org/components//version-3>
<ver:filename>?</ver:filename>
</ver:del>
{code}

The service does not return a message.

The service might return an Error when an element in the request is missing or if the SFTP connection failed.

The available exchange pattern is: InOnly.

h2. Configuration

All needed information must be defined in the service-unit JBI descriptor. This JBI descriptor is configured through parameters divided in following groups:
* *JBI parameters* that defines the service provider identification,
* *CDK parameters* that are parameters driving the service provider implementation at CDK layer,
* *CDK interceptor parameters* that are parameters driving interceptors at CDK layer,
* *Dedicated parameters* that are parameters driving the service provider implementation at component layer.

h3. CDK parameters defining service provider implementation
The following parameters correspond to the CDK configuration of the service provider implementation.

{include:0 CDK SU Provide Configuration 5.8.0}

h3. CDK parameters driving interceptors
The following parameters drive interceptors at CDK layer.

{include:0 CDK SU Interceptor configuration 5.8.0}

h3. Dedicated configuration
The following parameters correspond to the component specific configuration of the service provider implementation, divided in two groups:
* connection parameters,
* other parameters.

h4. Connection parameters

{anchor:connection-parameters}
{table-plus}
|| {center}Parameter{center} || {center}Description{center} || {center}Default{center} || {center}Required{center} || {center}Support placeholders{center} ||
| server | IP or DNS name of the server | {center}\-{center} | {center}Yes{center} {center}except when using Dynamic mode{center} | {center}Yes{center} |
| port | the port number of the server | {center}21{center} | {center}No{center} | {center}Yes{center} |
| user | the user login name used to connect to the server | {center}\-{center} | {center}Yes{center}{center}except when using Dynamic mode{center} | {center}Yes{center} |
| password | the user password | {center}\-{center} | {center}Yes{center}{center}except when using Dynamic mode{center} | {center}Yes{center} |
| privatekey | the path to the user's private key (on the PEtALS machine) | {center}\-{center} | {center}Yes{center}{center}except when using dynamic mode or password authentication{center} | {center}Yes{center} |
| passphrase | the passphrase matching the given private key | {center}\-{center} | {center}No{center} | {center}Yes{center} |
| {{max-idle-time}} | The max time, in milli-seconds of idle connections of the connection pool. | {center}10000{center} | {center}No{center} | {center}Yes{center} |
| {{max-connection}} | The maximum number of simultaneous connections allowed by the connection pool to a same FTP server. "{{-1}}" for unlimited number of connections. | {center}-1{center} | {center}No{center} | {center}Yes{center} |
{table-plus}

h4. Other parameters

{table-plus}
|| {center}Parameter{center} || {center}Description{center} || {center}Default{center} || {center}Required{center} || {center}Support placeholders{center} ||
| {{folder}} | the folder on the server | {center}\-{center} | {center}No{center} | {center}Yes{center} |
| {{overwrite}} | if '{{true}}' an existing remote file will be overwritten. If '{{false}}', the file is not copied and a fault is returned to the caller saying "The file already exists" | {center}false{center} | {center}No{center} | {center}Yes{center} |
| {{create-folder}} | if '{{true}}', the component have to create the remote folder to execute the operation if it does not already exist. If '{{false}}', and the remote directory does not exist, a fault is returned to the caller saying "The remote directory does not exist" | {center}false{center} | {center}No{center} | {center}No{center} |
{table-plus}

h3. Service unit content

The service unit has to contain the following elements, packaged in the archive:
* the META-INF/jbi.xml descriptor file as described above,
* it is also highly recommended to provide a WSDL description for service provider embedded in the service-unit. The service provider contract must implement the interface "\{http://petals.ow2.org/components/sftp/version-1}SFTP" defined in the abstract WSDL 'SFtpServiceInterface.wsdl' available as resource in the component archive.

{code}
service-unit.zip
+ META-INF
- jbi.xml (as defined above)
- service.wsdl (recommended)
{code}

h3. Example

An example of a Service Unit descriptor to provide an SFTP service:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<jbi:jbi version="1.0"
xmlns:generatedNs="http://petals.ow2.org/components/sftp/version-1"
xmlns:jbi="http://java.sun.com/xml/ns/jbi"
xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5"
xmlns:sftp="http://petals.ow2.org/components/sftp/version-1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<jbi:services binding-component="true">
<jbi:provides
interface-name="generatedNs:SftpInterface"
service-name="generatedNs:SftpService"
endpoint-name="SftpServiceEndpoint">

<!-- CDK specific elements -->
<petalsCDK:timeout>30000</petalsCDK:timeout>
<petalsCDK:validate-wsdl>true</petalsCDK:validate-wsdl>
<petalsCDK:forward-security-subject>false</petalsCDK:forward-security-subject>
<petalsCDK:forward-message-properties>false</petalsCDK:forward-message-properties>
<petalsCDK:forward-attachments>false</petalsCDK:forward-attachments>
<petalsCDK:wsdl>SftpService.wsdl</petalsCDK:wsdl>

<!-- Component specific elements -->
<sftp:host>192.168.1.206</sftp:host>
<sftp:port>22</sftp:port>
<sftp:user>user1</sftp:user>

<sftp:password>test</sftp:password>
<!-- Authentication is done either by password or by privatekey/passphrase
<sftp:privatekey></sftp:privatekey>
<sftp:passphrase></sftp:passphrase>-->
</jbi:provides>
</jbi:services>
</jbi:jbi>{code}

h1. The integration service

The component exposes directly a generic SFTP service without deploying a service unit (*Integration service mode*). This generic service can be deactivate removing the file '{{component.wsdl}}' from the component archive.

In integration service mode, parameters for the SFTP connection are set in the XML message request in a connection node added to the operation payload as following. See [connection parameters|#connection-parameters] for more details:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<sftp:... xmlns:sftp="http://petals.ow2.org/components/sftp/generic/version-1">
<sftp:connection>
<sftp:server>?</ver:server>
<sftp:port>?</ver:port>
<sftp:user>?</ver:user>

<!--Optional:-->
<sftp:password>?</sftp:password>
<sftp:folder>?</sftp:folder>
<sftp:passphrase>?</sftp:passphrase>
<sftp:private-key>?</sftp:private-key>
<sftp:overwrite>?</sftp:overwrite>
<sftp:create-folder>?</sftp:create-folder>
</ver:connection>
</sftp:...>
{code}

Example of a PUT request:
{code:lang=xml}
<sftp:put xmlns:sftp="http://petals.ow2.org/components/sftp/generic/version-1">
<sftp:body>xml body</sftp:body>
<sftp:filename>file name on the server</sftp:filename>

<sftp:connection>
<sftp:host>192.168.1.206</sftp:host>
<sftp:port>22</sftp:port>
<sftp:user>user1</sftp:user>
<sftp:password>test</sftp:password>
</sftp:connection>
</sftp:put>
{code}

h1. Configuring the component

The component can be configured through the parameters of its JBI descriptor file. These parameters are divided in following groups:
* *JBI parameters* that have not to be changed otherwise the component will not work,
* *CDK parameters* that are parameters driving the processing of the CDK layer,
* *Dedicated parameters* that are parameters specific to this component.

h2. CDK parameters
The component configuration includes the configuration of the CDK. The following parameters correspond to the CDK configuration.

{include:0 CDK Component Configuration Table 5.8.0}

h2. Interception configuration
{include:0 CDK Component Interceptor configuration 5.8.0}

h2. Dedicated configuration

No dedicated configuration parameter is available.

h1. Business monitoring

h2. MONIT traces

{include:0 CDK BC Business Monitoring Traces 5.8.0}

h2. Flow tracing activation

{include:0 CDK BC Provides Business Monitoring Flow Tracing Activation 5.8.0}

h1. Monitoring the component

h2. Using metrics

Several probes providing metrics are included in the component, and are available through the JMX MBean '{{org.ow2.petals:type=custom,name=monitoring_*<component-id>*}}', where {{*<component-id>*}} is the unique JBI identifier of the component.

h3. Common metrics

{include:0 CDK Component Monitoring Metrics 5.8.0}

h3. Dedicated metrics

No dedicated metric is available.

h2. Receiving alerts

Several alerts are notified by the component through notification of the JMX MBean '{{org.ow2.petals:type=custom,name=monitoring_*<component-id>*}}', where {{*<component-id>*}} is the unique JBI identifier of the component.

{tip}To integrate these alerts with Nagios, see [petalsesbsnapshot:Receiving Petals ESB defects in Nagios].{tip}

h3. Common alerts

{include:0 CDK Component Monitoring Alerts 5.6.0}

h3. Dedicated alerts

No dedicated alert is available.

h1. Troubleshooting

h2. Try to connect to the SFTP server using the same SSH stack

If you have *problem establishing a connection* with the SSH server, you can test your parameters with [the Petals BC SFTP tooling of Petals CLI 2.1.1 or upper|petalscli211:Petals BC SFTP tooling].
+Note+: The Petals CLI command use the same SSH stack than the component.

h2. Getting log from the SSH layer

The BC SFTP embeds [J2SSH|http://j2ssh.sourceforge.net/] as SSH client stack. You can configure the log of the SSH stack extending the [Petals ESB logging configuration|petalsesbsnapshot:Logging in Petals] with:
{code}
# The full J2SSH
com.sshtools.j2ssh.level=INFO

# J2SSH by parts
com.sshtools.j2ssh.sftp.level=INFO
com.sshtools.j2ssh.transport.level=WARNING
{code}
{note}Caution the J2SSH layer is verbose at {{INFO}} level !{note}