Camel Components

SCP

Since Camel 2.10

Only producer is supported

The Camel Jsch component supports the SCP protocol using the Client API of the Jsch project. Jsch is already used in camel by the FTP component for 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-jsch</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

scp://host[:port]/destination[?options]

The file name can be specified either in the <path> part of the URI or as a "CamelFileName" header on the message (Exchange.FILE_NAME if used in code).

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, *.yaml files, 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 SCP component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

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

autowiredEnabled (advanced)

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

verboseLogging (advanced)

Whether to log the INFO messages of JSch at INFO level. JSch logs much at INFO level, so by default the component logs these messages at DEBUG level. The component passes the JSch log messages, with the [JSCH] prefix, to its own logger.

false

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

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 SCP endpoint is configured using URI syntax:

scp:host:port/directoryName

With the following path and query parameters:

Path Parameters

Name Description Default Type

host (producer)

Required Hostname of the FTP server.

String

port (producer)

Port of the FTP server.

int

directoryName (producer)

The starting directory.

String

Query Parameters

Name Description Default Type

disconnect (common)

Whether or not to disconnect from remote FTP server right after use. Disconnect will only disconnect the current connection to the FTP server. If you have a consumer which you want to stop, then you need to stop the consumer/route instead.

false

boolean

checksumFileAlgorithm (producer)

If provided, then Camel will calculate a checksum from the file that has been written, and store the result in the CamelFileChecksum header.

Enum values:

  • MD2

  • MD5

  • SHA_1

  • SHA_224

  • SHA_256

  • SHA_384

  • SHA_512

  • SHA_512_224

  • SHA_512_256

  • SHA3_224

  • SHA3_256

  • SHA3_384

  • SHA3_512

String

chmod (producer)

The permissions of the file that the producer writes, as three octal digits, for example 644. Any other value is replaced by 664. The producer sends it in the scp protocol line of the file, and the remote scp uses it when it creates the file. The directories that the producer creates for a file name with a path get 775.

664

String

fileName (producer)

Use Expression such as File Language to dynamically set the filename. For consumers, it’s used as a filename filter: only a 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 producers, it’s used to evaluate the filename to write. If an expression is set, it take precedence over the CamelFileName header. (Note: The header itself can also be an Expression). The expression options support both String and Expression types. If the expression is a String type, it is always evaluated using the File Language. If the expression is an Expression type, the specified Expression type is used - this allows you, for instance, to use OGNL expressions. For the consumer, you can use it to filter filenames, so you can for instance consume today’s file using the File Language syntax: mydata-$\{date:now:yyyyMMdd}.txt. The producers support the CamelOverruleFileName header which takes precedence over any existing CamelFileName header; the CamelOverruleFileName is a header that is used only once, and makes it easier as this avoids to temporary store CamelFileName and have to restore it afterwards.

String

jailStartingDirectory (common)

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

checksumWriteFile (producer)

If checksumFileAlgorithm has been configured then this option controls whether to write a checksum file as well or not. The checksum file will always be written in the same folder as the original file.

true

boolean

flatten (producer)

Flatten is used to flatten the file name path to strip any leading paths, so it’s just the file name. This allows you to consume recursively into sub-directories, but when you eg write the files to another directory they will be written in a single directory. Setting this to true on the producer enforces that any file name in CamelFileName header will be stripped for any leading paths.

false

boolean

allowNullBody (producer (advanced))

Used to specify if a null body is allowed during file writing. If set to true then an empty file will be created, when set to false, and attempting to send a null body to the file component, a GenericFileWriteException of 'Cannot write null body to file.' will be thrown. If the fileExist option is set to 'Override', then the file will be truncated, and if set to append the file will remain unchanged.

false

boolean

disconnectOnBatchComplete (producer (advanced))

Whether or not to disconnect from remote FTP server right after a Batch upload is complete. disconnectOnBatchComplete will only disconnect the current connection to the FTP server.

false

boolean

lazyStartProducer (producer (advanced))

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

moveExistingFileStrategy (producer (advanced))

Strategy (Custom Strategy) used to move file with special naming token to use when fileExist=Move is configured. By default, there is an implementation used if no custom strategy is provided.

FileMoveExistingStrategy

browseLimit (advanced)

Maximum number of messages to keep in memory available for browsing. Use 0 for unlimited.

100

int

connectTimeout (advanced)

Sets the connect timeout for waiting for a connection to be established Used by both FTPClient and JSCH.

10000

int

soTimeout (advanced)

Sets the so timeout FTP and FTPS Is the SocketOptions.SO_TIMEOUT value in millis. Recommended option is to set this to 300000 so as not have a hanged connection. On SFTP this option is set as timeout on the JSCH Session instance.

300000

int

timeout (advanced)

Sets the data timeout for waiting for reply Used only by FTPClient.

30000

int

caSignatureAlgorithms (security)

A comma-separated list of the signature algorithms that are accepted for the CA signature of an OpenSSH host certificate, for example ssh-ed25519,rsa-sha2-512. The CA keys are the cert-authority entries of the known hosts file. If not set, the JSch default list is used, which does not accept the SHA-1 based ssh-rsa.

String

certBytes (security)

The OpenSSH user certificate as a byte array, for certificate-based authentication. Only used together with privateKeyFile or privateKeyBytes, and when neither certFile nor certUri is set.

byte[]

certFile (security)

The OpenSSH user certificate file for certificate-based authentication, for example id_ed25519-cert.pub. A path on the file system, or with the classpath: prefix a resource on the classpath. Only used together with privateKeyFile or privateKeyBytes, the private key of the certificate. Takes precedence over certUri and certBytes.

String

certUri (security)

Deprecated The OpenSSH user certificate for certificate-based authentication, loaded the same way as certFile: a path on the file system, or with the classpath: prefix a resource on the classpath. Only used together with privateKeyFile or privateKeyBytes, and when certFile is not set. Takes precedence over certBytes. Deprecation note: Use certFile, which loads the certificate in the same way and takes precedence.

String

knownHostsFile (security)

The known hosts file that JSch checks the key of the remote host against when the producer connects, in the OpenSSH known_hosts format. A path on the file system, or with the classpath: prefix a resource on the classpath. An cert-authority entry lets the producer accept an OpenSSH host certificate signed by that CA. What happens with a host that is not in the file, or whose key changed, depends on strictHostKeyChecking.

String

password (security)

Password to use for login.

String

preferredAuthentications (security)

A comma-separated list of the SSH authentication methods to try, in order of preference, for example publickey,password. JSch supports gssapi-with-mic, publickey, keyboard-interactive and password. If not set, the JSch default gssapi-with-mic,publickey,keyboard-interactive,password is used.

String

privateKeyBytes (security)

The private key as a byte array, for public key authentication. Only used when privateKeyFile is not set. Use privateKeyFilePassphrase for an encrypted key.

byte[]

privateKeyFile (security)

The private key file for public key authentication. A path on the file system, or with the classpath: prefix a resource on the classpath. The key must be in a format that JSch reads, such as OpenSSH, PEM or PuTTY. Takes precedence over privateKeyBytes. Use privateKeyFilePassphrase for an encrypted key.

String

privateKeyFilePassphrase (security)

The passphrase of an encrypted private key of privateKeyFile or privateKeyBytes. Not needed for a key that is not encrypted.

String

strictHostKeyChecking (security)

Sets whether to use strict host key checking. Setting this to 'no' (the default) disables host key verification and makes the connection vulnerable to man-in-the-middle attacks. Use 'yes' in production environments.

Enum values:

  • no

  • yes

no

String

username (security)

Username to use for login.

String

useUserKnownHostsFile (security)

Whether to use the known hosts file of the user, the .ssh/known_hosts file in the home directory (the user.home system property, or the HOME environment variable), when knownHostsFile is not set. If that file does not exist, or if false and knownHostsFile is not set, no host is known, and strictHostKeyChecking decides whether the producer connects.

true

boolean

ciphers (security (advanced))

A comma-separated list of the ciphers for the SSH connection, in order of preference, for example aes128-ctr,aes256-ctr. The cipher names are those of JSch. If not set, the JSch default list is used.

String

Message Body

The message body at each side of the SCP 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

Producer input

text, bytes, stream or file

The content of the file: text, bytes, a stream or a file, which is read into memory first to send its size. A Map or a List fails: marshal it first.

  • With allowNullBody=true: null, text, bytes, stream or file

Producer output

unchanged

Unchanged, with the name of the remote file in the CamelFileNameProduced header.

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

The SCP component copies the message body to a file on the remote host. In the following route, the file consumer sets the CamelFileName header, and each file of a local folder is copied to the /upload directory of the host. The host key is checked against a known hosts file:

- route:
    from:
      uri: file:outbox
      steps:
        - to:
            uri: scp://myhost:22/upload
            parameters:
              username: "{{scp.username}}"
              password: "{{scp.password}}"
              knownHostsFile: /home/camel/.ssh/known_hosts
              strictHostKeyChecking: "yes"

The directory of the endpoint (/upload above) must exist on the remote host, as scp does not create it: when it does not exist, each file is written to a file named like the directory, and the last one wins. The sub directories in the CamelFileName header (such as mysub/hello.txt) are created in that directory.

scp sends the name of each sub directory and of the file on a protocol line that ends with a line feed, so a file name with a line feed or a NUL character is refused with a GenericFileOperationFailedException before anything is sent to the remote host. Any other character, such as a carriage return or a tab, is sent as is.

Without a known hosts file (useUserKnownHostsFile=false and no knownHostsFile, or the default useUserKnownHostsFile=true when .ssh/known_hosts does not exist in the home directory), no host is known, so the option strictHostKeyChecking decides: with yes the connection fails, with no (the default) the host key is not checked.

With the password option the producer can log in with the password and the keyboard-interactive authentication methods. With keyboard-interactive, it answers with the password when the server asks one question that is not echoed and contains password: (in any case), as a PAM setup does, and cancels any other question.

OpenSSH Certificate Authentication

Camel supports OpenSSH certificate-based authentication for SCP connections, where a user’s public key is signed by a Certificate Authority (CA). This is configured using the certFile or certBytes parameters (or the deprecated certUri) alongside the private key:

  • Java

  • YAML

to("scp://host/path?username=myuser"
   + "&privateKeyFile=/path/to/user_key"
   + "&certFile=/path/to/user_key-cert.pub");
- route:
    from:
      uri: file:outbox
      steps:
        - to:
            uri: scp://host/path
            parameters:
              username: myuser
              privateKeyFile: /path/to/user_key
              certFile: /path/to/user_key-cert.pub

See the SFTP component documentation for more details on certificate authentication options.

Limitations

Currently, camel-jsch only supports a Producer (i.e., copy files to another host).