camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deepak_a <>
Subject Re: Problem with sFTP PUT (solved + Potential code enhancement?)
Date Thu, 03 Jul 2014 14:42:49 GMT

After going through the code - its now clear on why the PUT action failed.
As explained in my previous post - by sFTP server provider does not allow
command like CD to be run after logging in.

Following is my routes.xml

	    <from uri="file:src/data?move=.done"/>
	                            <setHeader headerName="CamelFileName">


After looking into the code I noticed the following.

1. after SSH session is established
2. WriteFile method of GenericFileProducer is invoked. If the target
directory is specified (in my case it is /put). then method buildDirectory
of class SftpOperations is invoked

            if (directory != null) {
                if (!operations.buildDirectory(directory, absolute)) {
                    log.debug("Cannot build directory [{}] (could be because
of denied permissions)", directory);

3. <extract from method: buildDirectory>

        try {
            // maybe the full directory already exists
            try {
                success = true;
            } catch (SftpException e) {
                // ignore, we could not change directory so try to create it

            if (!success) {
                LOG.debug("Trying to build remote directory: {}",

                try {
                    success = true;
                } catch (SftpException e) {
                    // we are here if the server side doesn't create
intermediate folders
                    // so create the folder one by one
                    success = buildDirectoryChunks(directory);
        } catch (IOException e) {
            throw new GenericFileOperationFailedException("Cannot build
directory: " + directory, e);
        } catch (SftpException e) {
            throw new GenericFileOperationFailedException("Cannot build
directory: " + directory, e);
        } finally {
            // change back to original directory
            if (originalDirectory != null) {

The strange (weird) thing I understood is - we check if the full directory
already exist by doing a
If that fails - then we ignore (because we are going to create it!!!!)
Then we make an attempt to create directory (channel.mkdir(directory)).
In the finally block we again try to change back to the original directory.

In my case - all these 3 action will fail - because my sFTP server provider
does not allow any of these actions to be taken.

The only option I have is to build my own sFTP component - as explained in

I now have 3 classes

and I set up my route end point as


Note: I am still curious to see how other users tackled scenarios where sFTP
server did not provide access to change directory (unless I have missed
something vital)


View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message