MINA SFTP
Since Camel 4.18
Both producer and consumer are supported
The MINA SFTP component provides access to remote file systems over the SFTP protocol using Apache MINA SSHD library.
This component is designed as a near drop-in replacement for the JSch-based sftp component, requiring only a URI scheme change from sftp:// to mina-sftp://. Most configuration options remain the same for supported features.
URI format
mina-sftp://[username@]host[:port]/directoryName[?options]
Where directoryName represents the underlying directory. The directory name is a relative path.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The MINA SFTP component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean |
Endpoint Options
The MINA SFTP endpoint is configured using URI syntax:
mina-sftp:host:port/directoryName
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether to transfer files in binary mode (true) or in ASCII mode (false). Only ftp and ftps use it: sftp and mina-sftp transfer the bytes of the file as they are. | false | boolean | |
The charset (encoding) of the file content, such as UTF-8. The consumer uses it when the file content is read as text, and the producer writes text with this charset. When writing, Camel may have to read the whole message into memory to convert it to the charset, so do not use it with big messages. | String | ||
Whether to disconnect from the remote server right after use: the consumer disconnects after each poll, and the producer after each message it writes. This only closes the current connection: to stop a consumer, stop the consumer or the route instead. | false | boolean | |
The name of the done file, an empty file that marks a file as complete. Producer: after the file is written, the done file is written in the same directory. Consumer: a file is only consumed when its done file exists in the same directory, and the done file is deleted once the file is consumed (unless noop=true). The name is either a fixed name, or uses the placeholders $\{file:name} and $\{file:name.noext}, which are the only ones supported; the consumer supports the fixed part of the name either as a prefix or as a suffix, not both. | String | ||
The file name, as an expression such as the File Language. Consumer: only the file with exactly this name is consumed, as the name is not a pattern (use antInclude or include to consume the files that match a pattern); for example consume the file of today with mydata-$\{date:now:yyyyMMdd}.txt. Producer: the name of the file to write; when set, it is used instead of the CamelFileName header, unless that header holds an org.apache.camel.Expression (a String header is used as it is, not evaluated). A String value of this option is evaluated with the File Language, and an Expression object as it is. The producer also supports the CamelOverruleFileName header, which takes precedence over the CamelFileName header and is used only once, so CamelFileName does not have to be stored and restored around the producer. | String | ||
Used for jailing (restricting) writing files to the starting directory (and sub) only. This is enabled by default to not allow Camel to write files to outside directories (to be more secured out of the box). You can turn this off to allow writing files to directories outside the starting directory, such as parent or root folders. For consumers that use a localWorkDirectory, this also restricts the downloaded files to stay within the configured localWorkDirectory. | true | boolean | |
Whether to use passive mode for the data connections, in which the client connects to the server, instead of active mode (the default), in which the server connects to the client. Only ftp and ftps use it. | false | boolean | |
The path separator to use in the paths that Camel sends to the server: UNIX replaces each backslash with a slash, Windows replaces each slash with a backslash, and Auto leaves the separators of the path as they are. Enum values:
| UNIX | PathSeparator | |
Whether ftp and ftps check that a file exists by listing only that file (true), instead of listing its directory and looking for the file name (false). Some FTP servers do not support listing a file directly. The changed read lock (readLock=changed) also uses this option to get the file information. Enabling it speeds up the check when the directory holds many files. The sftp and mina-sftp components check whether a file exists, also for readLock=changed, with a single request whatever the number of files, so this option makes no difference for them. | false | boolean | |
Whether to send a noop command to check that the connection is still valid, as a pre-write check before uploading files (producer) and before each poll (consumer), and for ftp and ftps also before renaming or deleting a file on the server, such as when the consumer moves or deletes a processed file. This is enabled by default, which allows to silently re-connect if the connection was lost. However if this causes problems, you can turn this option off, and then a lost connection may only be found when the next operation fails. For example a rename or delete after a long-running route then fails if the server closed the idle connection meanwhile, so the file stays and is polled again, unless an idempotent repository prevents that. | true | boolean | |
If true, the file is deleted after it is processed successfully. Cannot be combined with move. | false | boolean | |
Sets the move failure expression based on Simple language. For example, to move files into a .error subdirectory use: .error. Note: When moving the files to the fail location Camel will handle the error and will not pick up the file again. | String | ||
If true, the consumer leaves the file in place: it does not move or delete the file after it is processed (preMove and moveFailed still apply, and delete=true takes precedence over noop). Good for read-only data or ETL. noop=true also turns on idempotent (unless idempotent is set), so the same files are not consumed over and over again. | false | boolean | |
Expression (such as File Language) used to dynamically set the filename when moving it before processing. For example to move in-progress files into the order directory set this value to order. | String | ||
When pre-sort is enabled then the consumer will sort the file and directory names during polling, that was retrieved from the file system. You may want to do this in case you need to operate on the files in a sorted order. The pre-sort is executed before the consumer starts to filter, and accept files to process by Camel. This option is default=false meaning disabled. The following values are supported: name (sort by file name), modified (sort by last-modified timestamp), size (sort by file size). To sort in descending (reverse) order, prefix the value with a minus sign (e.g., -modified to sort newest first). The value true is an alias for name (backward compatible). Enum values:
| String | ||
Whether to also consume the files in all the subdirectories of the starting directory (see minDepth and maxDepth). | false | boolean | |
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
How the consumer downloads a file when no localWorkDirectory is set. When true, the message body is the stream of the remote file, which the route reads as the file is downloaded. When false, the whole file is loaded into memory before it is sent to the route. For ftp and ftps, stepwise must then be set to false, as both cannot be enabled at the same time. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the consumer downloads the file. When false, the message body is null, but the consumer still creates an exchange with the details of the file, such as its name and size, in the headers. | true | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Whether the consumer ignores a directory or file that does not exist, or that it has no permission for, when it lists a directory or downloads a file. By default, an exception is thrown. | false | boolean | |
A custom org.apache.camel.spi.IdempotentRepository that keeps track of the files being consumed, so that a later poll does not pick up a file that is still in progress. By default, a memory based repository (of up to 50000 entries) is used. | IdempotentRepository | ||
A local directory to download the remote files into, so their content is stored in local files instead of in memory. Useful to save memory when consuming very big files. Not used by the file component. | String | ||
A custom org.apache.camel.spi.ExceptionHandler that handles the exceptions thrown when the consumer completes a file, by a commit or a rollback (such as moving or deleting the file). By default, the exceptions are logged at WARN level and ignored. | ExceptionHandler | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special ready file exists. If this option is set then the readLock option does not apply. | GenericFileProcessStrategy | ||
Whether the consumer throws an exception when it cannot connect or log in to the server, or cannot create the starting directory. By default, the consumer logs a WARN and skips the poll. When enabled, the exception goes to the rollback method of the poll strategy (the pollStrategy option), which can handle it. | false | boolean | |
Whether the consumer lists the directory on the server to find the files to download (the LIST command for ftp and ftps). Set it to false when the server does not allow listing: the consumer then only downloads the file named by the fileName option, which must be set, and the file has no meta-data such as size, timestamp and permissions, as only a listing gives them. | true | boolean | |
The algorithm of a checksum to calculate from the content of the written file. The checksum is set in the CamelFileChecksum header (and written to a checksum file, see checksumWriteFile). The name is passed to java.security.MessageDigest, which accepts names such as MD5, SHA-1, SHA-256 or SHA3-256. Enum values:
| String | ||
Whether to also write the checksum to a file, when checksumFileAlgorithm is set. The checksum file is written in the same directory as the file, with the algorithm as extension (for example hello.txt.MD5 with checksumFileAlgorithm=MD5). | true | boolean | |
What to do when a file with the same name already exists: - Override - replaces the existing file (the default). - Append - adds the content to the existing file. - Fail - fails with a GenericFileOperationFailedException. - Ignore - keeps the existing file and writes nothing, without failing. - Move - moves the existing file to the name given by the moveExisting option (which must be set) before writing the file. The eagerDeleteTargetFile option controls what happens when a file already exists at that name. - TryRename - only used with tempFileName or tempPrefix: renames the temporary file to the real name without checking whether a file exists, which can be faster on some file systems and FTP servers. Enum values:
| Override | GenericFileExist | |
Whether to strip the leading paths from the file name, so only the name of the file is left. The consumer then sets the CamelFileName header to the name only, and the producer strips the paths from the name it writes (from the fileName option or the CamelFileName header). For example, files consumed recursively from subdirectories are then all written in a single directory. | false | boolean | |
Expression (such as File Language) used to compute file name to use when fileExist=Move is configured. To move files into a backup subdirectory just enter backup. This option only supports the following File Language tokens: file:name, file:name.ext, file:name.noext, file:onlyname, file:onlyname.noext, file:ext, and file:parent. Notice the file:parent is not supported by the FTP component, as the FTP component can only move any existing files to a relative directory based on current dir as base. | String | ||
The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. The location for tempFilename is relative to the final file location in the option 'fileName', not the target directory in the base uri. For example if option fileName includes a directory prefix: dir/finalFilename then tempFileName is relative to that subdirectory dir. | String | ||
This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files. | String | ||
Whether a message with a null body can be written. If true, an empty file is written: an existing file is truncated with fileExist=Override, and left unchanged with fileExist=Append. If false, a null body fails with a GenericFileOperationFailedException. | false | boolean | |
The permissions to set on each file that the producer uploads, as an octal number, for example 640. | String | ||
The permissions to set on each directory that Camel creates on the server, as an octal number, for example 750. | String | ||
Whether the producer disconnects from the remote server after the last message of a batch, which is a message whose exchange property CamelBatchComplete is true, such as the last file of a poll of a file consumer. This only closes the current connection. | false | boolean | |
Whether to delete an existing target file before the temporary file is written, when fileExist=Override is used with tempFileName or tempPrefix. Set it to false to keep the existing target file while the temporary file is written, for example when writing big files: the target file is then deleted just before the temporary file is renamed to it. With fileExist=Move, it also controls what happens when a file already exists at the name given by moveExisting: true deletes that file before the move, false fails the move with an exception. | true | boolean | |
Whether to set the last modified timestamp of the written file to the value of the CamelFileLastModified header (a java.util.Date or a long), for example to keep the timestamp of the source file. Nothing is set when the header is missing. Only used by the file component. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
A custom FileMoveExistingStrategy that moves the existing file when fileExist=Move is used. By default, the component uses its own implementation, which moves the file to the name computed by moveExisting. | FileMoveExistingStrategy | ||
Automatically create missing directories in the file’s pathname. For the file consumer, that means creating the starting directory. For the file producer, it means the directory the files should be written to. | true | boolean | |
The address (host name or IP address) of the local network interface that the connection binds to. The mina-sftp component also accepts a local port, as host:port. | String | ||
Maximum number of messages to keep in memory available for browsing. Use 0 for unlimited. | 100 | int | |
For sftp, the number of requests that JSch may have outstanding at any one time during a file transfer (the JSch default is 16). Increasing this value may slightly improve the transfer speed, but uses more memory. The mina-sftp component turns it into a buffer size of this number times 32 KB. | Integer | ||
Whether to compress the data with zlib, if the server supports it. 0 (the default) turns compression off. For sftp, the value is the compression level, from 1 (fastest) to 9 (best compression). The mina-sftp component ignores the level: any value greater than 0 enables compression. | int | ||
The timeout in milliseconds for establishing the connection to the server. For sftp, mina-sftp and scp, it also applies to the SSH handshake and the login. 0 means no timeout. | 10000 | int | |
Deprecated Deprecated: JSch-specific parameter, ignored by mina-sftp. mina-sftp checks whether a directory exists with an SFTP stat request. | Boolean | ||
The character encoding of the file names on the server, such as UTF-8 (the default). | String | ||
Deprecated Deprecated: JSch-specific parameter, ignored by mina-sftp. Configure logging via your logging framework instead. | String | ||
The maximum number of attempts to connect to the remote server each time a connection is needed, reconnectDelay apart. Default is 3. 0 or less means a single attempt. A login that the server rejects is not retried. | int | ||
The read buffer size in bytes. Camel sets it as the Apache MINA SSHD session property sftp-fs-read-buffer-size, which only the SFTP file system of Apache MINA SSHD reads, not the SFTP client that this component uses. So this option currently has no effect: files are read in chunks of the SSH channel packet size. | Integer | ||
The delay in milliseconds between two attempts to connect to the remote server. | 1000 | long | |
The number of keep-alive messages that may be sent without receiving anything back from the server. When this number is reached, the connection is closed. For mina-sftp, it only applies when serverAliveInterval is greater than 0, and 0 means no limit. | 1 | int | |
The interval in milliseconds for sending keep-alive messages to the server. 0 (the default) turns it off; for sftp, soTimeout then applies instead. For sftp, JSch sends a keep-alive message when the server sent nothing during this interval. For mina-sftp, a keep-alive message is sent at each interval. | int | ||
Deprecated Deprecated: JSch-specific parameter, ignored by mina-sftp. Configure logging via your logging framework instead. | String | ||
The socket timeout (SO_TIMEOUT) in milliseconds, so that a connection whose server no longer answers does not hang. For ftp and ftps, it is the read timeout of the control connection: a command whose reply does not come within this time fails. For sftp, it is the timeout of the JSch session: when the server sends nothing for this time, JSch sends a keep-alive message, and closes the connection after serverAliveCountMax such messages; it is not used when serverAliveInterval is set. The mina-sftp and scp components do not use it. 0 means no timeout. | 300000 | int | |
Whether to change directory one level at a time when traversing directories to download files, and when uploading a file to a directory. When disabled, the file operations use the full path instead, for example when the server does not allow changing directory. For ftp and ftps, stepwise cannot be used together with streamDownload. | true | boolean | |
The data timeout in milliseconds. For ftp and ftps, it is the read timeout of the data connection (the data timeout of the Apache Commons Net FTPClient), and 0 means no timeout. For scp, it is the timeout of the JSch session. The sftp and mina-sftp components do not use it. | 30000 | int | |
The write buffer size in bytes. Camel sets it as the Apache MINA SSHD session property sftp-fs-write-buffer-size, which only the SFTP file system of Apache MINA SSHD reads, not the SFTP client that this component uses. So this option currently has no effect: files are written in chunks of the SSH channel packet size. | Integer | ||
Excludes the files whose path, relative to the starting directory, matches one of these Ant style patterns, such as */.bak. Separate several patterns with a comma. Takes precedence over antInclude. | String | ||
Whether the antInclude and antExclude patterns are matched case sensitive. | true | boolean | |
Includes only the files whose path, relative to the starting directory, matches one of these Ant style patterns, such as */.txt. Separate several patterns with a comma. | String | ||
Allows for controlling whether the limit from maxMessagesPerPoll is eager or not. If eager then the limit is during the scanning of files, and the file, sftp, mina-sftp and smb consumers stop reading the directory once the limit is hit, unless preSort or doneFileName is used, as they need the whole directory. Where as false would scan all files, and then perform sorting. Setting this option to false allows for sorting all files first, and then limit the poll. Mind that this requires a higher memory usage as all file details are in memory to perform the sorting. | true | boolean | |
Excludes the files whose name matches this regular expression (matched ignoring the case). Takes precedence over include. It is a regular expression, not a wildcard: use antExclude for wildcards, or excludeExt to exclude files by extension. When the expression has characters such as the plus sign, set it with RAW() in an endpoint URI. | String | ||
Excludes the files with one of these extensions (ignoring the case), separated by comma, for example excludeExt=bak,dat. A file matches when its name ends with a dot and the extension, so both excludeExt=gz and excludeExt=tar.gz match mydata.tar.gz. For more flexibility use the include and exclude options. | String | ||
Pluggable filter as a org.apache.camel.component.file.GenericFileFilter class. Will skip files if filter returns false in its accept() method. | GenericFileFilter | ||
A File Language predicate that filters the subdirectories to scan with recursive=true: only the directories for which it is true are scanned. For example, to scan only the directory of today: $\{file:onlyname} == $\{date:now:yyyyMMdd}. | String | ||
A File Language predicate that filters the files: only the files for which it is true are consumed. For example, to filter on the file extension: $\{file:ext} == 'txt'. | String | ||
Option to use the Idempotent Consumer EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If noop=true then idempotent will be enabled as well to avoid consuming the same files over and over again. Setting only idempotentRepository or idempotentKey does not turn it on. | false | Boolean | |
Sets whether to eagerly add the filename to the idempotent repository or wait until the exchange is complete. Does not apply with an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename), which adds the filename when it acquires the lock. | true | Boolean | |
To use a custom idempotent key. By default the absolute path of the file is used. You can use the File Language, for example to use the file name and file size, you can do: idempotentKey=$\{file:name}-$\{file:size}. It is used only with idempotent=true (noop=true turns it on), or by an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename) of the file component. | String | ||
A pluggable repository org.apache.camel.spi.IdempotentRepository which by default use MemoryIdempotentRepository if none is specified and idempotent is true. It is used only with idempotent=true (noop=true turns it on), or by an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename) of the file component. Set without them, it does not skip any file. | IdempotentRepository | ||
Includes only the files whose name matches this regular expression (matched ignoring the case). It is a regular expression, not a wildcard: use antInclude for wildcards, or includeExt to include files by extension. When the expression has characters such as the plus sign, set it with RAW() in an endpoint URI. | String | ||
Includes only the files with one of these extensions (ignoring the case), separated by comma, for example includeExt=txt,xml. A file matches when its name ends with a dot and the extension, so both includeExt=gz and includeExt=tar.gz match mydata.tar.gz. For more flexibility use the include and exclude options. | String | ||
The maximum depth to traverse when recursively processing a directory. maxDepth=1 means only the starting directory. | 2147483647 | int | |
The maximum number of files to consume in one poll. 0 or negative (the default) means no limit. Can be used, for example, to avoid picking up thousands of files at once when the server starts. With eagerMaxMessagesPerPoll=true (the default) the limit applies while the files are scanned, before any sorting: with 100000 files and maxMessagesPerPoll=500, the first 500 files found are taken and then sorted. Set eagerMaxMessagesPerPoll=false to scan and sort all the files first, and then take the limit. | int | ||
The minimum depth to start processing when recursively processing a directory. Using minDepth=1 means the base directory. Using minDepth=2 means the first sub directory. | int | ||
Expression (such as Simple Language) used to dynamically set the filename when moving it after processing. To move files into a .done subdirectory just enter .done. | String | ||
A custom org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy to use as the read lock. When set, the readLock option is not used. | GenericFileExclusiveReadLockStrategy | ||
The read lock strategy, so that the consumer only picks up a file that is not being written (in progress). The consumer waits for the read lock up to readLockTimeout. The strategies are: - none - no read lock is used. - changed - uses the length and the modification timestamp of the file to detect whether it is still being written, so files cannot be consumed as fast as with the others. The option readLockCheckInterval sets the time between two checks. - rename - tries to rename the file, to test whether the consumer can get an exclusive read lock. The other read locks of the file component (markerFile, fileLock and the idempotent read locks) are not supported, and fail when the consumer is created. Enum values:
| none | String | |
The interval in millis between the attempts to acquire the read lock, for the read locks that retry (changed, fileLock and rename, and also idempotent-changed and idempotent-rename of the file component). For example, set a higher interval with readLock=changed to cater for slow writes. The ftp, ftps, sftp, mina-sftp and azure-files components use 5000 by default. readLockTimeout must be higher than readLockCheckInterval; as a rule of thumb, make the timeout at least 2 or 3 times the interval, so the read lock has enough time to be acquired before the timeout. | 1000 | long | |
The logging level of the message logged when a read lock cannot be acquired, for example OFF for no logging. Used by the read locks changed, fileLock, idempotent, idempotent-changed, idempotent-rename and rename. Enum values:
| DEBUG | LoggingLevel | |
Whether the changed, fileLock and rename read locks also create a marker file, to keep other processes from picking up the same files. Set it to false, for example, to not write marker files to the file system. Only used by the file component. | true | boolean | |
The minimum age in millis a file must have before the changed read lock (readLock=changed or idempotent-changed) acquires it, for example readLockMinAge=300s for 5 minutes. When set, the read lock acquires a file as soon as it is older than this, without waiting for its length and timestamp to stay the same, which can make it faster. | 0 | long | |
The minimum length in bytes a file must have before the changed read lock (readLock=changed or idempotent-changed) acquires it. The default 1 means an empty file is not consumed; set 0 to consume empty files. | 1 | long | |
The timeout in millis to acquire the read lock. When the lock is not granted within the timeout, the file is skipped and tried again on the next poll. 0 or lower waits forever. Used by the changed, fileLock and rename read locks (and also idempotent-changed and idempotent-rename of the file component). The ftp, ftps, sftp, mina-sftp and azure-files components use 20000 by default. readLockTimeout must be higher than readLockCheckInterval; as a rule of thumb, make the timeout at least 2 or 3 times the interval, so the read lock has enough time to be acquired before the timeout. | 10000 | long | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
If knownHostsFile does not exist, then attempt to auto-create the path and file (beware that the file will be created by the current user of the running Java process, which may not have file permission). | false | boolean | |
Set the OpenSSH certificate as a byte array for certificate-based authentication. | byte[] | ||
Set the OpenSSH certificate file path for certificate-based authentication. | String | ||
Set the OpenSSH certificate (loaded from classpath by default) for certificate-based authentication. | String | ||
Comma-separated list of the ciphers to offer to the server, in order of preference, for example aes256-gcmopenssh.com,chacha20-poly1305openssh.com,aes256-ctr. The names are those of Apache MINA SSHD; an unknown or unsupported name fails the connection. If not set, the default list of Apache MINA SSHD is used. | String | ||
Comma-separated list of the key exchange algorithms to offer to the server, in order of preference, for example curve25519-sha256,ecdh-sha2-nistp256. The names are those of Apache MINA SSHD; an unknown or unsupported name fails the connection. If not set, the default list of Apache MINA SSHD is used. | String | ||
A key pair of the public and private key, for public key authentication. | KeyPair | ||
Sets the known_hosts from the byte array, so that the SFTP endpoint can do host key verification. | byte[] | ||
Sets the known_hosts file, so that the SFTP endpoint can do host key verification. | String | ||
Sets the known_hosts file (loaded from classpath by default), so that the SFTP endpoint can do host key verification. | String | ||
Password to use for login. | String | ||
The authentication methods to try, as a comma-separated list in order of preference, for example publickey,password. When not set, the default list of the SSH library is used. | String | ||
The private key as a byte array, for public key authentication. | byte[] | ||
The private key file, for public key authentication. | String | ||
The passphrase of the private key of privateKeyFile, privateKeyUri or privateKey, when the private key is encrypted. | String | ||
The private key (loaded from classpath by default), for public key authentication. | String | ||
The public key algorithms that are accepted for public key authentication, as a comma-separated list. When not set, the default list of the SSH library is used. | String | ||
Comma-separated list of the server host key algorithms to offer to the server, in order of preference, for example ssh-ed25519,rsa-sha2-512,ecdsa-sha2-nistp256. The names are those of Apache MINA SSHD; an unknown or unsupported name fails the connection. If not set, the default list of Apache MINA SSHD is used. | String | ||
Custom ServerKeyVerifier for host key verification. When provided, this verifier is used exclusively, ignoring strictHostKeyChecking, knownHostsFile, and other host key options. | ServerKeyVerifier | ||
Sets whether to use strict host key checking. Setting this to 'no' (the default) disables host key verification and makes SFTP connections vulnerable to man-in-the-middle attacks. Use 'yes' in production environments. Enum values:
| no | String | |
The user name to log in with. For ftp and ftps, the login is anonymous when it is not set. | String | ||
If knownHostsFile has not been explicitly configured, then use the host file from System.getProperty(user.home)/.ssh/known_hosts. | true | boolean | |
To shuffle the list of files (sort in random order). | false | boolean | |
Sorts the files with File Language expressions, such as sortBy=file:name. Separate several groups with a semicolon to sort by the next group when the previous one is equal, such as sortBy=file:modified;file:name. Prefix a group with reverse: to sort it in reverse order, and with ignoreCase: to compare text ignoring the case (reverse: comes first when both are used). | String | ||
Pluggable sorter as a java.util.Comparator class that compares org.apache.camel.component.file.GenericFile objects. | Comparator |
Message Headers
The MINA SFTP component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | A long value containing the file size. | long | |
CamelFileLastModified (consumer) Constant: | A Long value containing the last modified timestamp of the file. | long | |
| Constant: | Only the file name (the name with no leading paths). | String | |
| Constant: | (producer) Specifies the name of the file to write (relative to the endpoint directory). This name can be a String; a String with a file or simple Language expression; or an Expression object. If it’s null then Camel will auto-generate a filename based on the message unique ID. (consumer) Name of the consumed file as a relative file path with offset from the starting directory configured on the endpoint. | String | |
CamelFileNameConsumed (consumer) Constant: | The name of the file that has been consumed. | String | |
| Constant: | Whether the path of the consumed file is absolute (true), or relative (false). | Boolean | |
CamelFileAbsolutePath (consumer) Constant: | The absolute path to the file. For relative files this path holds the relative path instead. | String | |
| Constant: | The file path. For relative files this is the starting directory. For absolute files this is the absolute path. | String | |
CamelFileRelativePath (consumer) Constant: | The relative path. | String | |
| Constant: | The parent path. | String | |
CamelFileNameProduced (producer) Constant: | The path and name of the file that the producer wrote: the starting directory of the endpoint followed by the file name. This header is set by Camel, to provide the name of the file that was written. | String | |
CamelOverruleFileName (producer) Constant: | Is used for overruling CamelFileName header and use the value instead (but only once, as the producer will remove this header after writing the file). The value can only be a String. Notice that if the option fileName has been configured, then this is still being evaluated. | Object | |
CamelFileLocalWorkPath (consumer) Constant: | Path to the local work file, if local work directory is used. | String | |
CamelRemoteFileInputStream (consumer) Constant: | The input stream of the remote file, when the consumer uses streamDownload=true. | InputStream | |
| Constant: | The remote hostname. | String | |
| Constant: | The reply code of the last operation on the server. For ftp and ftps, it is the reply code of the FTP server. For sftp, it is the SFTP status code, 0 when the operation succeeded. The mina-sftp component does not set it. | int | |
| Constant: | The reply text of the last operation on the server. For ftp and ftps, it is the reply text of the FTP server. For sftp, it is OK when the operation succeeded, or the error message. The mina-sftp component does not set it. | String |
Message Body
The message body at each side of the MINA SFTP component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The file as read: a RemoteFile, which converts to text, bytes or a stream; a stream with streamDownload; with preMove its content, a byte array.
Not known when |
Producer input |
| What converts to an InputStream: text, bytes, a stream or a file. A Map or a List fails: marshal it first.
|
Producer output |
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Sub-Pages
For detailed documentation on specific topics, see:
-
Authentication - Password, public key, certificates, and authentication priority
-
SSH Security - Host key verification, ciphers, key exchange protocols, and algorithm recommendations
-
Migration from JSch - Migration guide, behavioral differences, deprecated parameters, and logging
Username Resolution
When no username is specified in the URI, the mina-sftp component follows the same username resolution order as the JSch-based camel-sftp component, matching standard SSH client behavior.
Resolution Priority Order
| Priority | Source | Description |
|---|---|---|
1 (highest) | URI parameter | Username specified directly in URI: |
2 | SSH config file |
|
3 (lowest) | OS username |
|
SSH Config Resolution
The component reads the user’s ~/.ssh/config file (if it exists) and applies matching Host entries. For example:
# ~/.ssh/config
Host myserver.example.com
User deployuser
Host *.internal.example.com
User admin
Host *
User defaultuser With this configuration: * mina-sftp://myserver.example.com/path uses username deployuser * mina-sftp://app.internal.example.com/path uses username admin * mina-sftp://other.example.com/path uses username defaultuser
OS Username Fallback
If the SSH config file exists but does not contain a User directive for the target host, the component falls back to the operating system username (System.getProperty("user.name")).
The OS username fallback only occurs when the SSH config file exists. If no ~/.ssh/config file exists at all, the connection will fail with "No username specified when the session was created". |
Explicit Username Recommended
For production deployments, always specify the username explicitly in the URI to ensure predictable behavior across different environments:
-
Java
-
XML
-
YAML
// Recommended: explicit username
from("mina-sftp://deployuser@host/path?password=secret")
.to("file:local");
// Not recommended: relies on SSH config or OS username
from("mina-sftp://host/path?password=secret")
.to("file:local"); <!-- Recommended: explicit username -->
<route>
<from uri="mina-sftp://deployuser@host/path?password=secret"/>
<to uri="file:local"/>
</route>
<!-- Not recommended: relies on SSH config or OS username -->
<route>
<from uri="mina-sftp://host/path?password=secret"/>
<to uri="file:local"/>
</route> # Recommended: explicit username
- route:
from:
uri: mina-sftp://deployuser@host/path
parameters:
password: secret
steps:
- to:
uri: file:local
# Not recommended: relies on SSH config or OS username
- route:
from:
uri: mina-sftp://host/path
parameters:
password: secret
steps:
- to:
uri: file:local Compatibility with camel-sftp
This username resolution behavior is identical to the JSch-based camel-sftp component, ensuring seamless migration. Both components:
-
Check the URI for an explicit username first
-
Fall back to
~/.ssh/configif no username in URI -
Fall back to OS username if SSH config exists but has no
Userdirective
Examples
Upload Files
-
Java
-
XML
-
YAML
from("file:inbox")
.to("mina-sftp://user@sftp.example.com/upload?password=secret"); <route>
<from uri="file:inbox"/>
<to uri="mina-sftp://user@sftp.example.com/upload?password=secret"/>
</route> - route:
from:
uri: file:inbox
steps:
- to:
uri: mina-sftp://user@sftp.example.com/upload
parameters:
password: secret Download Files
-
Java
-
XML
-
YAML
from("mina-sftp://user@sftp.example.com/download?password=secret&delete=true")
.to("file:outbox"); <route>
<from uri="mina-sftp://user@sftp.example.com/download?password=secret&delete=true"/>
<to uri="file:outbox"/>
</route> - route:
from:
uri: mina-sftp://user@sftp.example.com/download
parameters:
password: secret
delete: true
steps:
- to:
uri: file:outbox Poll and Move
-
Java
-
XML
-
YAML
from("mina-sftp://user@host/inbox?password=secret&move=.done")
.to("file:local"); <route>
<from uri="mina-sftp://user@host/inbox?password=secret&move=.done"/>
<to uri="file:local"/>
</route> - route:
from:
uri: mina-sftp://user@host/inbox
parameters:
password: secret
move: .done
steps:
- to:
uri: file:local Filter by Extension
-
Java
-
XML
-
YAML
from("mina-sftp://user@host/data?password=secret&antInclude=*.csv")
.to("direct:process-csv"); <route>
<from uri="mina-sftp://user@host/data?password=secret&antInclude=*.csv"/>
<to uri="direct:process-csv"/>
</route> - route:
from:
uri: mina-sftp://user@host/data
parameters:
password: secret
antInclude: "*.csv"
steps:
- to:
uri: direct:process-csv Using Local Work Directory
Camel supports consuming from remote SFTP servers and downloading the files directly into a local work directory, with the localWorkDirectory option. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using FileOutputStream.
Camel will store to a local file with the same name as the remote file, though with .inprogress as the extension while the file is being downloaded. Afterward, the file is renamed to remove the .inprogress suffix. And finally, when the Exchange is done (also when it failed), the local file is deleted. If the download itself fails, the partly written .inprogress file is deleted at once.
So if you want to download files from a remote SFTP server and store them as files, then you need to route to a file endpoint such as:
-
Java
-
XML
-
YAML
from("mina-sftp://user@sftp.example.com/download?password=secret&localWorkDirectory=/tmp")
.to("file:inbox"); <route>
<from uri="mina-sftp://user@sftp.example.com/download?password=secret&localWorkDirectory=/tmp"/>
<to uri="file:inbox"/>
</route> - route:
from:
uri: mina-sftp://user@sftp.example.com/download
parameters:
password: secret
localWorkDirectory: /tmp
steps:
- to:
uri: file:inbox The java.io.File handle of the local work file is the message body. The first file producer of the route uses a java.io.File.rename to move the local work file to its target, instead of a file copy, as the work file is meant to be deleted anyway.
After that rename, the message body still names the local work file, which is gone. A later step that reads the file again fails, such as a second file producer or a convertBodyTo. Another exchange that keeps the java.io.File body, for example from a wireTap or an aggregate, finds the file deleted once the original exchange is done. Convert the body before such a step, for example with convertBodyTo(byte[].class), which reads the file into memory. |
from("mina-sftp://user@sftp.example.com/download?password=secret&localWorkDirectory=/tmp")
.convertBodyTo(byte[].class)
.to("file:inbox")
.to("file:archive"); Read locks
The mina-sftp consumer supports the read locks none, rename and changed. readLock=false and readLock=off mean none. Any other readLock value, such as the markerFile, fileLock, idempotent, idempotent-changed and idempotent-rename read locks of the File component, fails when the consumer is created, also with poll and pollEnrich, with IllegalArgumentException: ReadLock invalid. The readLock option is not checked when a custom exclusiveReadLockStrategy or processStrategy is set, as it does not apply then.
Checking whether a file exists
The mina-sftp component checks whether a remote file exists with a single lstat request, whatever the number of files in the directory. This applies to fileExist=Ignore, Fail and Move, to tempFileName and tempPrefix, to a producer doneFileName, and to readLock=changed, which reads the size and modification time of the file with the same request on every check. So the fastExistsCheck option makes no difference for these checks with mina-sftp.
The answer comes from the server for the path itself. A symbolic link is not followed, as in a directory listing: a dangling link exists, and readLock=changed compares the size and modification time of the link, not those of its target.
When the server answers the request with another status than "no such file", for example because it does not permit or support it on the path, the component lists the directory instead and compares the names. When the server does not answer that listing either, or the connection fails, the check fails with an error, rather than answering that the file is missing.
Error Handling
Connection Retry
-
Java
-
XML
-
YAML
from("mina-sftp://user@host/path?password=secret&maximumReconnectAttempts=5&reconnectDelay=2000")
.to("file:local"); <route>
<from uri="mina-sftp://user@host/path?password=secret&maximumReconnectAttempts=5&reconnectDelay=2000"/>
<to uri="file:local"/>
</route> - route:
from:
uri: mina-sftp://user@host/path
parameters:
password: secret
maximumReconnectAttempts: 5
reconnectDelay: 2000
steps:
- to:
uri: file:local Error Messages
The component provides clear error messages for common failure scenarios:
Connection Errors
-
Host unreachable:
Cannot connect to {host}:{port} -
Connection timeout:
Connection timed out after {timeout}ms
Authentication Errors
-
Login rejected (wrong credentials):
Login rejected by {host}:{port}: No more authentication methods availableWhen the server definitively rejects the credentials,
mina-sftpthrowsGenericFileOperationFailedExceptionimmediately, without retrying. Transient connection failures (server unreachable, network error) are still retried up tomaximumReconnectAttemptstimes. -
Authentication timeout:
Authentication timed out after {timeout}ms
Configuration Errors
-
Invalid chmod:
Invalid chmod value: '999'. Must be a valid octal number (e.g., 644, 755) -
Invalid cipher:
Unknown or unsupported cipher: xxx. Available ciphers: [aes128-ctr, aes256-ctr, …] -
Invalid key exchange:
Unknown or unsupported key exchange protocol: xxx. Available protocols: [curve25519-sha256, …] -
Invalid host key algorithm:
Unknown or unsupported server host key algorithm: xxx. Available algorithms: [ssh-ed25519, …]
Host Key Verification Errors
-
Unknown host:
Host key verification failed: server 'hostname:port' is not in the known_hosts file -
Key mismatch:
Host key verification failed: the host key for 'hostname:port' has changed! -
Expired certificate:
Host certificate has expired. Valid until <date>, current time: <date>
Compression
The mina-sftp component supports SSH data compression to reduce bandwidth usage for large file transfers over slow or metered connections.
To enable compression, set the compression option to a value between 1 and 10:
from("mina-sftp://user@host/path?password=secret&compression=5")
.to("file:local"); When compression is enabled, the component configures the following algorithms in order of preference:
-
zlib@openssh.com(OpenSSH delayed compression - preferred for security) -
zlib(standard zlib compression) -
none(fallback if server doesn’t support compression)
If the server does not support compression, the connection falls back to uncompressed transfer and logs a WARNING.
Unlike the JSch-based sftp component which requires manually adding a zlib JAR to the classpath, Apache MINA SSHD includes built-in compression support. No additional dependencies are needed. |
By default (compression=0), compression is disabled to minimize CPU overhead.
Connection Keep-Alive
The component supports SSH keep-alive (heartbeat) functionality to prevent connections from being dropped during long idle periods and to detect unresponsive servers.
Configuration Options
| Option | Default | Type | Description |
|---|---|---|---|
|
| int (ms) | Interval in milliseconds between keep-alive messages. Set to |
|
| int | Maximum number of consecutive unanswered keep-alive messages before the connection is terminated. |
Preventing Connection Drops
// Send keep-alive every 30 seconds, terminate after 3 unanswered (90s max detection time)
from("mina-sftp://user@host/path?password=secret&serverAliveInterval=30000&serverAliveCountMax=3")
.to("file:local"); Behavioral Difference: serverAliveCountMax with Zero or Negative Values
There is a behavioral difference between mina-sftp and sftp components when serverAliveCountMax is set to 0 or a negative value. |
| Value | mina-sftp (MINA SSHD) | sftp (JSch) |
|---|---|---|
| Terminate connection after N unanswered heartbeats | Terminate connection after N unanswered heartbeats |
| Fire-and-forget mode: heartbeats sent but no reply expected | No keep-alive messages are sent |
| Same as | No keep-alive messages are sent |
Always use positive values for serverAliveCountMax for consistent behavior when migrating.
Local Interface Binding
In multi-homed environments (servers with multiple network interfaces), specify which local network interface the SFTP connection should use:
from("mina-sftp://user@host/path?password=secret&bindAddress=192.168.1.100")
.to("file:local"); Bind Address Formats
| Format | Example | Description |
|---|---|---|
IPv4 address |
| Bind to IP, ephemeral port |
IPv4 with port |
| Bind to IP and specific port |
IPv6 address |
| Bind to IPv6, ephemeral port |
IPv6 with port |
| Bind to IPv6 and port (bracketed notation) |
Hostname |
| Bind to hostname, ephemeral port |
Port specification is a mina-sftp enhancement not available in the JSch-based sftp component. |
When bindAddress is not specified, the operating system’s routing table determines which local interface is used.
SFTP Buffer Size Configuration
Configure buffer sizes for SFTP read and write operations to optimize file transfer performance:
// Configure 64KB read buffer and 32KB write buffer
from("mina-sftp://user@host/path?password=secret&readBufferSize=65536&writeBufferSize=32768")
.to("file:local"); | Option | Default | Description |
|---|---|---|
| MINA default | Buffer size in bytes for reading data from SFTP connections |
| MINA default | Buffer size in bytes for writing data to SFTP connections |
The maximum recommended buffer size is 126976 bytes (~124KB). Larger values may cause data corruption in Apache MINA SSHD. |
The deprecated bulkRequests parameter is still accepted for backward compatibility but new configurations should use readBufferSize and writeBufferSize directly.
TCP_NODELAY
The component sets TCP_NODELAY on its connections, as the JSch-based sftp component does.
Apache MINA SSHD leaves TCP_NODELAY off by default. A small request, such as one that reads the next part of a directory listing or deletes a file, would then wait for the server to acknowledge the previous reply (Nagle’s algorithm and delayed acknowledgements). A consumer sends many such requests: an OpenSSH server returns about 100 entries per directory listing request.
In a benchmark against an OpenSSH server on the same host, with maxMessagesPerPoll=1000:
-
one poll of a directory of 10,000 files took 66 ms with
TCP_NODELAYoff and 18 ms with it on; -
consuming and deleting 5,000 files took 2.1 s with it off and 1.5 s with it on.
The org.apache.sshd.config.tcp-nodelay system property of Apache MINA SSHD does not apply to the connections of this component.
File and Directory Permissions (chmod)
Set POSIX file permissions on uploaded files and created directories:
// Set file permissions to rw-r--r-- (644) and directory permissions to rwxr-xr-x (755)
from("file:/data/outbound")
.to("mina-sftp://user@host/uploads?password=secret&chmod=644&chmodDirectory=755"); Common permission values:
| Value | Permissions | Description |
|---|---|---|
|
| Owner full, group/others read+execute |
|
| Owner read+write, group/others read-only |
|
| Owner read+write only |
Values are validated at endpoint startup. Invalid values cause a clear error message.
The chmod and chmodDirectory options only work on POSIX-compatible SFTP servers. Windows SFTP servers may ignore these settings. |
Directory permissions and the setgid bit
With chmodDirectory, Camel sends a chmod request for each directory it creates, also for the intermediate directories of the path. The server decides what the request does. On a POSIX server, chmod silently clears the setgid bit (such as 2770) when the user is not a member of the group that owns the directory, and the server still replies with success. This happens, for example, when a directory is created below a setgid parent: it inherits the group of the parent, and a user outside that group ends with 770 instead of 2770. A directory created afterwards below it gets the primary group of the user instead, so it keeps the bit and the result looks inconsistent.
To keep the setgid bit on all the directories, add the user of the SFTP connection to the group that owns the directory, or make that group the primary group of the user.
Symbolic Links
The consumer follows symbolic links to their target files, within the starting directory unless jailStartingDirectory=false (see below). The producer writes to symlink targets.
With jailStartingDirectory enabled (the default), the consumer resolves a listed file that the server reports as a symbolic link before it accepts the file, one path segment at a time with the lstat and readlink requests. A link whose target is outside the starting directory, or cannot be resolved (such as a dangling link), is skipped and logged at WARN the first time. A link whose target contains a backslash (\) is skipped too, as a server may take it as a path separator or as part of a name. Links that resolve inside the starting directory, and a starting directory that is itself a link, work as usual. Set jailStartingDirectory=false to follow links to other directories, such as the links in data below when data is the starting directory. Only the files that the listing reports as links are resolved (a server that lists the attributes of the target instead does not show them as links), and the check and the download that follows are not atomic, so the permissions and link settings of the SFTP server still matter.
| Absolute symlinks in chroot environments: If the SFTP server uses a chroot jail, absolute symlinks may not resolve correctly. Use relative symlinks for maximum compatibility. |
# Relative symlink (works in chroot) - RECOMMENDED
ln -s ../actual-data/file.txt data/link.txt
# Absolute symlink (may fail in chroot)
ln -s /home/user/actual-data/file.txt data/link.txt Thread Safety
The mina-sftp component handles thread safety internally. The underlying MINA SSHD session and SFTP client are not thread-safe, so the component uses internal locking to ensure safe concurrent access.
Multiple Camel routes can safely share the same SFTP endpoint. Each endpoint maintains its own connection. For high-throughput scenarios, consider using multiple endpoints.
Filename Encoding
By default, MINA SSHD uses UTF-8 encoding for filenames. For legacy servers using different regional encodings, configure the filenameEncoding option:
// Connect to a legacy server using GBK encoding for Chinese filenames
from("mina-sftp://user@host/path?password=secret&filenameEncoding=GBK")
.to("file:local"); Supported encodings include GBK, GB2312, Shift-JIS, EUC-JP, ISO-8859-1, and Windows-1252.