Skip navigation


The SFTP Transport allows files to be read and written to and from directories over SFTP.  Unlike the VFS Transport, it can handle large files because it streams message payloads

The SFTP connector is based on the JSCH 0.1.29 library.

Versions of the SFTP Transport are available for each major version of Mule:

Mule Version Distribution Source Code
1.3.3 n/a
http://svn.muleforge.org/mule-transport-sftp/tags/1.3.3/
1.4.x http://dist.muleforge.org/mule-transport-sftp/1.4.3/ http://svn.muleforge.org/mule-transport-sftp/trunk/
2.0.x http://dist.muleforge.org/mule-transport-sftp/2.0.1/ http://svn.muleforge.org/mule-transport-sftp/branches/mule-2.0.x/

An Installation Guide is also available. More examples can be found in the Functional Tests section below.


SFTP Connector Properties

Property Description Default Required
pollingFrequency The frequency in milliseconds that the read directory should be checked. Note that the read directory is specified by the endpoint of the listening component. 1000 No
filenameParser Is an implementation of org.mule.providers.file.FilenameParserand is used to control how filename patterns are used to generate file names. The file provider has a default implementation called org.mule.providers.file.SimpleFilenameParser that understands the following patterns:
  • ${DATE}- the current date in the format dd-MM-yy_HH-mm-ss.SS
  • ${DATE:yy-MM-dd}- the current date using the specified format
  • ${SYSTIME}- The current system time milliseconds
  • ${UUID}- A generated Universally unique id
  • ${ORIGINALNAME}- The original file name if the file being written was read from another location
  • ${COUNT}- An incremental counter
org.mule.providers.file. SimpleFilenameParser Yes
outputPattern The default pattern to use when writing a file to the VFS filesystem. This can use the patterns supported by the filenameParser configured for this connector. 
You can also override this pattern by explicitly setting a property on the Mule message (use the key SftpConnector.PROPERTY_FILENAME).

Yes
autoDelete Determines whether to delete the file in the read directory after it has been processed
true No


SFTP Endpoints

SFTP endpoints are expressed using the standard URI of:
sftp://<username>:<password>@<host>/path/to/dir

For example, the SFTP endpoint could be configured as follows: sftp://mule:test123@myhost.com/tmp/sftp

This endpoint would connect over SFTP to myhost.com as mule/test123, then read or write to ~/tmp/sftp.


Streaming Payloads

The default payload for messages received from SFTP inbound endpoints is an SftpInputStream (which implements InputStream).  When SftpInputStream is closed, the SFTP connection which supported the stream is also closed.  Use the InputStreamByteArray transformer below if you are working with a small payload and prefer to not work with streams.

Messages sent to and SFTP outbound endpoint can be an InputStream, String, or byte[].


Transformers

Transformer Description
org.mule.providers.sftp.transformers.InputStreamByteArray
Materializes an InputStream into a byte array

This transformer makes it possible to use the SFTP Message Receiver with non-streaming Service Components or Message Dispatchers.  Typical usage is to add this transformer to an SFTP receiving endpoint, so that downstream Service Components or Message Dispatchers can deal with a byte[] instead of InputStream.  Note however that materializing an InputStream for a large file will cause OOM errors, so this transformer should not be used if large files are expected.


Functional Tests

JUnit Class
Description
org.mule.providers.sftp.LargeFileReceiveFunctionalTestCase
Tests ability of the SftpMessageReceiver to receive a large file.   The file is received by a Service Component (ReceiveLargeFileTestHelperComponent) which streams the file to the /tmp directory.
org.mule.providers.sftp.LargeFileSendFunctionalTestCase Tests ability of the SftpMessageDispatcher to send a large file.   The file is streamed from /tmp/big.zip on the local machine.
org.mule.providers.sftp.SendReceiveFunctionalTestCase Tests a round trip send/receive of multiple files.
Adaptavist Theme Builder Powered by Atlassian Confluence