SFTP
Since Camel 1.1
Both producer and consumer are supported
This component provides access to remote file systems over the SFTP protocol.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> 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 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 | |
Whether to create the known_hosts file, and its directory, when it does not exist. The file is created by the user that runs the Java process, which may not have the permission to create it. | false | boolean | |
Sets the known_hosts from the byte array globally, so that the SFTP endpoints can do host key verification. | byte[] | ||
Sets the known_hosts file globally, so that the SFTP endpoints can do host key verification. | String | ||
Sets the known_hosts file (loaded from classpath by default) globally, so that the SFTP endpoints can do host key verification. | String | ||
Sets whether to use strict host key checking globally for all endpoints. 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 | |
Whether the SFTP endpoints use the known_hosts file of the user (.ssh/known_hosts in the home directory of the user) when knownHostsFile, knownHostsUri and knownHosts are not set. | true | boolean |
Endpoint Options
The SFTP endpoint is configured using URI syntax:
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 | |
The logging level for the log messages of JSch. WARN by default, as JSch logs a lot at INFO level. JSch has one logger for all the SFTP endpoints, so the level of the endpoint that connected last applies. Enum values:
| WARN | LoggingLevel | |
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 | |
Whether to check if a directory exists by listing it (ls) instead of changing into it (cd), before Camel creates it. A listing does not change the current directory, while with cd Camel has to change back afterwards. Disable it for servers where listing the directory does not work for this check, as reported on some Windows servers. | true | boolean | |
The character encoding of the file names on the server, such as UTF-8 (the default). | 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 | ||
A JSch proxy (com.jcraft.jsch.Proxy, such as ProxyHTTP, ProxySOCKS4 or ProxySOCKS5) through which Camel connects to the SFTP server. | Proxy | ||
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 | ||
The logging level for the messages to show to the user that JSch receives during the connection, such as the login banner of the server. Raise it when troubleshooting to see these messages in the log. Enum values:
| DEBUG | LoggingLevel | |
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 | |
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 a comma separated list of CA signature algorithms accepted for host certificate verification. If not specified the default list from JSch will be used (matches OpenSSH 8.2+ defaults). | String | ||
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 | ||
A comma-separated list of the ciphers that JSch proposes to the server, in order of preference, such as aes128-gcmopenssh.com,aes256-ctr. The names are those of JSch. If not set, the default list of JSch is used. | String | ||
A comma-separated list of the key exchange algorithms that JSch proposes to the server, in order of preference, such as curve25519-sha256,ecdh-sha2-nistp256. The names are those of JSch. If not set, the default list of JSch 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 | ||
A comma-separated list of the algorithms for the host key of the server that JSch accepts, in order of preference, such as ssh-ed25519,ecdsa-sha2-nistp256,rsa-sha2-512. If not set, the default list of JSch is used. | String | ||
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 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 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.
Usage
URI format and paths
sftp://[username@]hostname[:port]/directoryname[?options]
The directoryname is relative to the directory the user logs in to, usually its home directory. For example, sftp://admin@host/inbox uses the inbox directory in the home directory of admin.
Absolute paths are not supported. The component removes the leading slashes, also from sftp://host//data/inbox, and logs a WARN: that endpoint uses data/inbox under the login directory, not /data/inbox. As both the consumer and the producer create a missing directory (autoCreate=true, the default), a wrong path does not fail: the files are read from, or written to, a new directory under the login directory.
To use a directory outside the login directory, either:
-
create a symbolic link to it in the login directory, and use the link as
directoryname, or -
go up with leading
../segments, such assftp://host/../shared/inbox, and setjailStartingDirectory=false. With the defaultjailStartingDirectory=true, the consumer skips every file of such a directory, and the producer refuses to write to it.
For the producer, directoryname is the directory to write to, and the file name comes from the CamelFileName header or the fileName option. A file name that leaves the directory with ../ is refused unless jailStartingDirectory=false.
Security Best Practices: Host Key Verification
By default, the SFTP component has strictHostKeyChecking=no, which disables host key verification and makes connections vulnerable to man-in-the-middle (MITM) attacks. For production environments, you should enable strict host key checking to ensure you are connecting to the expected server. |
Global Configuration (Component Level)
You can configure host key verification settings globally on the SFTP component, which will apply to all SFTP endpoints unless overridden at the endpoint level:
SftpComponent configuration via `CamelContext`// Configure component for all SFTP endpoints
SftpComponent sftp = context.getComponent("sftp", SftpComponent.class);
sftp.setStrictHostKeyChecking("yes");
sftp.setKnownHostsFile("/path/to/known_hosts");
// All endpoints will inherit these settings
from("sftp://host1/path1?username=user1&password=secret1")
.to("direct:result");
from("sftp://host2/path2?username=user2&password=secret2")
.to("direct:result"); Or with application.properties configuration:
camel.component.sftp.strict-host-key-checking=yes
camel.component.sftp.known-hosts-file=/path/to/known_hosts Per-Endpoint Configuration
Host key verification prevents MITM attacks by verifying the server’s host key against a known list of trusted keys. When strictHostKeyChecking=yes is enabled, the SFTP client will reject connections to servers whose host key is not in the known hosts file.
Endpoint-level configurations will override component-level settings. This allows you to set secure defaults globally while making exceptions for specific endpoints if needed.
To enable strict host key checking at the endpoint level, set strictHostKeyChecking=yes and provide a known hosts file:
-
Java
-
XML
-
YAML
from("sftp://host:22/path?username=myuser&password=secret&knownHostsFile=/path/to/known_hosts&strictHostKeyChecking=yes")
.to("direct:result"); <route>
<from uri="sftp://host:22/path?username=myuser&password=secret&knownHostsFile=/path/to/known_hosts&strictHostKeyChecking=yes"/>
<to uri="direct:result"/>
</route> - route:
from:
uri: sftp://host:22/path
parameters:
username: myuser
password: secret
knownHostsFile: /path/to/known_hosts
strictHostKeyChecking: "yes"
steps:
- to:
uri: direct:result Alternatively, load the known hosts from the classpath:
-
Java
-
XML
-
YAML
from("sftp://host:22/path?username=myuser&privateKeyFile=/path/to/id_rsa&knownHostsUri=classpath:known_hosts&strictHostKeyChecking=yes")
.to("direct:result"); <route>
<from uri="sftp://host:22/path?username=myuser&privateKeyFile=/path/to/id_rsa&knownHostsUri=classpath:known_hosts&strictHostKeyChecking=yes"/>
<to uri="direct:result"/>
</route> - route:
from:
uri: sftp://host:22/path
parameters:
username: myuser
privateKeyFile: /path/to/id_rsa
knownHostsUri: "classpath:known_hosts"
strictHostKeyChecking: "yes"
steps:
- to:
uri: direct:result If you do not have a known hosts file, you can create one by connecting to the server using the ssh command, which will add the host key to ~/.ssh/known_hosts. By default, the SFTP component will use this file if useUserKnownHostsFile=true (which is the default).
-
Java
-
XML
-
YAML
from("sftp://host:22/path?username=myuser&privateKeyFile=/path/to/id_rsa&strictHostKeyChecking=yes")
.to("direct:result"); <route>
<from uri="sftp://host:22/path?username=myuser&privateKeyFile=/path/to/id_rsa&strictHostKeyChecking=yes"/>
<to uri="direct:result"/>
</route> - route:
from:
uri: sftp://host:22/path
parameters:
username: myuser
privateKeyFile: /path/to/id_rsa
strictHostKeyChecking: "yes"
steps:
- to:
uri: direct:result When strictHostKeyChecking=yes is enabled, Camel’s security policy enforcement framework will not flag this as a security violation. The default strictHostKeyChecking=no may trigger warnings or failures depending on your configured security policy. |
Providing the private key
For public key authentication, set the private key with one of these options:
| Option | Value |
|---|---|
| A path on the file system, such as |
| A resource, loaded from the classpath by default, or from the file system with the |
| The key as a |
| A |
Set privateKeyPassphrase when the key is encrypted. It applies to privateKeyFile, privateKeyUri and privateKey.
The key must keep its line breaks. A key whose line breaks were replaced, for example with spaces when it was copied into a one-line property or environment variable, fails with invalid privatekey. Load such a key from a file instead, or from a bean that holds the original bytes.
OpenSSH Certificate Authentication
Camel supports OpenSSH certificate-based authentication for SFTP connections, where a user’s public key is signed by a Certificate Authority (CA) rather than being individually authorized on the server. This is common in enterprise environments using tools like HashiCorp Vault or custom CA infrastructure.
To use certificate authentication, provide the certificate file alongside the private key:
-
Java
-
XML
-
YAML
from("sftp://host:22/path?username=myuser&privateKeyFile=/path/to/user_key&certFile=/path/to/user_key-cert.pub")
.to("direct:result"); <route>
<from uri="sftp://host:22/path?username=myuser&privateKeyFile=/path/to/user_key&certFile=/path/to/user_key-cert.pub"/>
<to uri="direct:result"/>
</route> - route:
from:
uri: sftp://host:22/path
parameters:
username: myuser
privateKeyFile: /path/to/user_key
certFile: /path/to/user_key-cert.pub
steps:
- to:
uri: direct:result The certificate can also be loaded from a classpath resource using certUri:
-
Java
-
XML
-
YAML
from("sftp://host:22/path?username=myuser&privateKeyFile=/path/to/user_key&certUri=classpath:user_key-cert.pub")
.to("direct:result"); <route>
<from uri="sftp://host:22/path?username=myuser&privateKeyFile=/path/to/user_key&certUri=classpath:user_key-cert.pub"/>
<to uri="direct:result"/>
</route> - route:
from:
uri: sftp://host:22/path
parameters:
username: myuser
privateKeyFile: /path/to/user_key
certUri: "classpath:user_key-cert.pub"
steps:
- to:
uri: direct:result Or provided as raw bytes using certBytes (useful when the certificate is loaded programmatically, e.g., from a vault).
When a certificate is loaded, Camel automatically adds the certificate’s key type to JSch’s PubkeyAcceptedAlgorithms if it is not already present. This ensures certificate authentication works even when the key type has been removed from JSch’s defaults due to SHA-1 deprecation (e.g., ssh-rsa-cert-v01@openssh.com). Both the legacy vendor-prefixed key type names (<algorithm>-cert-v01@openssh.com, used through draft-03) and the standardized short names (<algorithm>-cert, introduced in draft-04) are recognized. If you need to control the CA signature algorithms that JSch will accept, use the caSignatureAlgorithms parameter. |
Post-Quantum Key Exchange
The SFTP client proposes the hybrid post-quantum key exchange mlkem768x25519-sha256 ahead of the classical groups, so a connection to a server that offers it is protected against harvest-now-decrypt-later attacks without any configuration. ML-KEM is implemented either by the JDK, from Java 24 on, or by Bouncy Castle, which camel-ftp brings on the classpath for the Java 21 baseline. Where neither is available, the group is dropped from the proposal and the handshake falls back to a classical key exchange.
The server decides as much as the client does. jsch proposes only mlkem768x25519-sha256 by default, so a server that offers sntrup761x25519-sha512@openssh.com alone, such as OpenSSH before 9.9, takes the connection back to a classical key exchange unless that group is added to keyExchangeProtocols, and a server that offers no hybrid group does so in any case. To require the post-quantum exchange, and fail rather than fall back, pin the proposal to the hybrid groups:
sftp://localhost/inbox?username=admin&keyExchangeProtocols=mlkem768x25519-sha256,sntrup761x25519-sha512@openssh.com keyExchangeProtocols replaces the proposal rather than adding to it, so an endpoint that pins a list of classical groups never negotiates a post-quantum one. Check any value configured before Camel 4.24, and add mlkem768x25519-sha256, and sntrup761x25519-sha512@openssh.com for the servers before OpenSSH 9.9, to the front of it.
The same applies to the ssh component through its kex option. The scp component (camel-jsch) has no endpoint option for the proposal: the jsch.kex system property sets it for the whole JVM.
Restoring Deprecated Key Types and Algorithms
As of Camel 3.17.0, key types and algorithms that use SHA1 are disabled by default: JSch no longer proposes the ssh-rsa and ssh-dss host keys, ssh-rsa signatures for public key authentication, or SHA1 key exchanges such as diffie-hellman-group14-sha1. If your server needs them, set them on the endpoint with these options:
| Option | Algorithms (JSch configuration key) |
|---|---|
| Host keys ( |
| Signatures for public key authentication ( |
| Key exchange ( |
| Ciphers ( |
Each option replaces the default list of JSch for that endpoint, so list every algorithm the endpoint may use, the preferred one first. For example, for a server that has an RSA host key and only accepts ssh-rsa signatures:
sftp://host/inbox?username=admin&privateKeyFile=/path/to/id_rsa&serverHostKeys=rsa-sha2-512,rsa-sha2-256,ssh-rsa&publicKeyAcceptedAlgorithms=rsa-sha2-512,rsa-sha2-256,ssh-rsa The options apply to that endpoint only. Setting the JSch configuration directly changes the defaults of the whole JVM, so of every SFTP endpoint without these options:
JSch.setConfig("server_host_key", JSch.getConfig("server_host_key") + ",ssh-rsa");
JSch.setConfig("PubkeyAcceptedAlgorithms", JSch.getConfig("PubkeyAcceptedAlgorithms") + ",ssh-rsa");
JSch.setConfig("kex", JSch.getConfig("kex") + ",diffie-hellman-group1-sha1,diffie-hellman-group14-sha1"); Note that the key types and algorithms your server supports may differ than the above example. You can use the following command to inspect your server’s configuration:
ssh -vvv <server_address>
Connection errors
When the connection fails, the exception is a GenericFileOperationFailedException with the message Cannot connect to sftp://user@host:port. The message of its cause, from JSch, tells what failed, and the consumer logs it in its WARN Cannot connect/login to: sftp://user@host:port due to: …:
| Message of the cause | What to check |
|---|---|
| With |
| JSch and the server have no algorithm in common. Add one that the server proposes with |
| The server refused the credentials: check the username, password or key. With an RSA key and a server that only accepts |
| JSch cannot read the key, for example because its line breaks were lost. See Providing the private key. |
|
|
A login that the server rejects is not retried, as each rejected login counts towards the lockout policy of a server, such as one that locks the account after a few failures. Camel gives the password once per connection, with the password or the keyboard-interactive method: when the server asks for it again, the connection ends with Auth fail for user '…': the server did not accept the password. So a server that asks for the password twice in one login, such as one that requires both the password and the keyboard-interactive methods (AuthenticationMethods password,keyboard-interactive in OpenSSH), rejects the login, with the same message, even when the password is right. A rejected login (Auth fail … or Auth cancel …) does not connect again for maximumReconnectAttempts, which applies to the other connection failures. The consumer tries again on its next poll, so a wrong password is sent once per poll (and once more when the consumer starts with autoCreate=true), and the producer tries again on its next message.
Operation errors
When the server refuses a request, such as a change of directory, a listing, an upload or a download, the exception is a GenericFileOperationFailedException whose message ends with the status of the server, for example Cannot list directory: inbox: SSH_FX_NO_SUCH_FILE: No such file. As with the reply of an FTP server, getCode() returns the SFTP status code, such as 2 for SSH_FX_NO_SUCH_FILE or 3 for SSH_FX_PERMISSION_DENIED, and getReason() its text. JSch reports an I/O failure as SSH_FX_FAILURE (4), with that failure as the cause.
When the change to a relative directory fails, the message also gives the current directory, which the path starts from, such as Cannot change directory to: inbox: SSH_FX_NO_SUCH_FILE: No such file. The path is relative to the current directory: /home/admin. The directory of the endpoint starts from the login directory, see URI format and paths.
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 and the starting directory
With jailStartingDirectory enabled (the default), the consumer resolves a listed file that the server reports as a symbolic link before it accepts the file. 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.
The link is resolved on the server one path segment at a time, with the lstat and readlink requests, so each listed link takes a few more requests per poll; other files take none. Only the files that the listing reports as links are resolved: OpenSSH and Apache MINA SSHD list a link as a link, but a server that lists the attributes of the target instead does not show it as a link, and with useList=false there is no listing. The check and the download that follows are not atomic, so the permissions and link settings of the SFTP server still matter.
Read locks
The 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.
Timeouts and dead connections
The SFTP endpoint opens the connection with connectTimeout (10 seconds) and uses soTimeout (5 minutes) as the read timeout of the JSch session. When nothing arrives from the server for soTimeout, JSch sends a keep-alive message and waits once more; it drops the session after serverAliveCountMax (1 by default) keep-alive messages without an answer. A connection that went silent (the host is gone, or a firewall or NAT drops the packets) is therefore noticed after about twice soTimeout: about 10 minutes with the defaults, during which the consumer or producer using it waits. These durations are how JSch behaves, approximately, not guarantees of Camel.
Lower soTimeout to notice it sooner; soTimeout=15000 notices it after about 30 seconds. As a server that is alive answers the keep-alive message, a command that takes longer than soTimeout does not drop the session.
sftp://scott@sftp.example.com/inbox?password=RAW(tiger)&connectTimeout=5000&soTimeout=15000&throwExceptionOnConnectFailed=true When serverAliveInterval is set, it replaces soTimeout as the read timeout of the session: the session is then dropped after about serverAliveInterval × (serverAliveCountMax + 1) without data from the server.
As with FTP, set throwExceptionOnConnectFailed=true so that a consumer that cannot connect fails its poll and its health check reports it DOWN, and upload under a temporary name (tempPrefix or tempFileName) so that a broken upload does not leave a truncated file under its final name. See Noticing a dead or silent server and Uploads interrupted by a broken connection.
Checking whether a file exists
The 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 no longer makes a difference for these checks with 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=changedcompares the size and modification time of the link, not those of its target. -
A server on a case-insensitive file system, such as one backed by Windows or macOS, finds a file whose name differs only in case, which the upload would replace.
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, as before. This listing is the same with and without fastExistsCheck.
More Information
For more information, you can look at the FTP component.