简体   繁体   English

Java Camel FTP上传

[英]Java Camel FTP Upload

First, sorry for my bad english. 首先,对不起我的英语不好。

The problem is I can not upload a file (.xls) file on a local FTP server. 问题是我无法在本地FTP服务器上上传文件(.xls)文件。

This is the Exception : 这是例外:

[org.apache.camel.component.file.GenericFileOperationFailedException - Error writing file GAS_EAV_EMV.xls]

This is my route : 这是我的路线:

<route id="sendFtp">
    <from uri="direct:sendFtp"/>
    <setHeader headerName="CamelFileName">
        <simple>GAS_EAV_EMV.xls</simple>
    </setHeader>
    <process ref="egssisFtpProcessor"/>
    <to uri="ftp://foo@127.0.0.1:21/?password=pwd"/>
</route>

Here my Processor to attach the file : 这是我的处理器要附加的文件:

public class EgssisFtpProcessor implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
        exchange.getIn().addAttachment(filename, new DataHandler(new FileDataSource(filename)));
    }
}

The exchange object has the attachment at the end of the processor. 交换对象在处理器末端具有附件。

It works with the SMTP protocol but not with FTP. 它适用于SMTP协议,但不适用于FTP。

Any idea ? 任何想法 ?

Server log : 服务器日志:

[14:29:29] - [78] Connecté à 127.0.0.1. Collecte du Nom d'utilisateur.
[14:29:29] - [78] Usager FOO Connecté IP: 127.0.0.1
[14:29:29] - [78] FOO : Répertoire en Cours: C:\tmp\
[14:29:29] - [78] Client 127.0.0.1 Déconnecté (00:00:00 Min)

Attachements is not used. 不使用附件。 Instead just set the message body to a java.io.File for the file you want to upload. 而是将消息正文设置为要上传文件的java.io.File。

exchange.getIn().setBody(new File(filename));

And since you use XML you may want to do this without any java code. 并且由于您使用XML,所以您可能需要没有任何Java代码的情况。 You can use the message translator EIP to convert the message body to a java.io.File with the header as the file name. 您可以使用消息翻译器EIP将消息正文转换为以标头作为文件名的java.io.File。

<transform>
    <simple resultType="java.io.File">${header.CamelFileName}</simple>
</transform>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM