ftpapache-camelbindy

Camel Apache FTP Looses LF


I have a issue with camel apache. My csv file has LF and CRLF in it. The LF is present in the values of my csv file. When camel gets my file from the ftp and put it on my desktop, the LF is no more there. But i need the LF character to format correctly my csv and cosume it with the bindy component.

  from("timer://products?fixedRate=true&period="+ TimeUnit.SECONDS.toMillis(30))
            .pollEnrich()
            .simple("ftp://"+ftpUsername+"@"+ftpServer+"?password="+ftpPassword+"&passiveMode=true&stepwise=true&delay=1000&delete=true&include=.*sensopur_product\\.csv$")
            .process(exchange -> {
                System.out.println(exchange.getIn().getBody());
                String value = exchange.getIn().getHeader("CamelFileName").toString();
                if (value != null && !value.equals("")){
                    exchange.getIn().setHeader("nomFichier",value);
                }else {
                    exchange.getIn().setHeader("nomFichier","pas de fichier");
                }
                exchange.getIn().setBody(exchange.getIn().getBody(String.class));

            })
            .setHeader("nomFichier", simple("${in.header.CamelFileName}"))

            .to("file://../sensopur/src/main/resources/static")
           .end();

csv with lf in values

How can i do to keep the LF when camel apache gets my file on the FTP server ? Thanks.


Solution

  • Add binary=true in ftp consumer line. This will stop ftp consumer convert the end-line character when collect file from server.

    i.e.

    .simple("ftp://"+ftpUsername+"@"+ftpServer+"?password="+ftpPassword+"&passiveMode=true&binary=true&stepwise=true&delay=1000&delete=true&include=.*sensopur_product\\.csv$")
    

    How does it work?

    The option binary is an option to switch between FTP protocol's binary/ASCII mode. By default, camel will use ASCII mode (binary=false).

    Under FTP protocol's ASCII mode, the FTP client is suppose to convert the end-line character of the file when across different OS type. For example, end-line character will change to LF when file moving from non-Unix system to Unix system.

    Under FTP protocol's binary mode, the FTP client is suppose to NOT convert any end-line character.