javastreambytefilestreamcamel-ftp

How to write byte or stream to Apache Camel FTP to transfer file


In my code currently, I get data from the database and then I write a file out of the data. I have this kind of camel route and working solution:-

private static final String INPUT_FILE_DIRECTORY_URI = "file:" + System.getProperty("user.home")
        + "/data/cdr/?noop=false";

private static final String SFTP_SERVER = "sftp://" +System.getProperty("user.name")
        + "@sftp_server_url/data/cdr/?privateKeyFile=~/.ssh/id_rsa&passiveMode=true";

from(INPUT_FILE_DIRECTORY_URI)
            .streamCaching()
            .log("Sending file to local sftp")
            .to(SFTP_SERVER); 

I don't want to write a file in the local disk. Instead, I want to write file data directly to the SFTP server. I don't know how to do it? But I imagine it should be possible to do it. Can you tell me is it possible? If yes, how to do it?


Solution

  • I managed to solve this problem in another way. It is more suitable for my particular problem.

                 byte[] csvData = csvStringBuilder.toString().getBytes();
                 Routes.withProducer(producer)
                        .withHeader(Exchange.FILE_NAME, myCsvFile.csv)
                        .withBody(csvData)
                        .to(SFTP_SERVER).request(byte[].class);