2

I have, I suppose, really newbie question but the fact is I'm newbie in spring framework. How can I upload files to, for example 'upload' folder loceted in root directory of my ftp server? I have tried this: My application context file:

<bean id="ftpClientFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="127.0.0.1"/>
    <property name="username" value="test"/>
    <property name="password" value="test"/>
    <property name="clientMode" value="0"/>
    <property name="fileType" value="2"/>
    <property name="bufferSize" value="10000"/>                 
</bean>

<int:channel id="ftpChannel"/>

<int-ftp:outbound-channel-adapter id="outFtpAdapter"
                                channel="ftpChannel"
                                session-factory="ftpClientFactory"
                                remote-directory="/Users/test"/>

and my java code:

ConfigurableApplicationContext context = 
            new FileSystemXmlApplicationContext("/src/citrus/resources/citrus-context.xml");
    MessageChannel ftpChannel = context.getBean("ftpChannel", MessageChannel.class);
    File file = new File("/Users/test/test.txt");
    Message<File> fileMessage = MessageBuilder.withPayload(file).build();
    ftpChannel.send(fileMessage);
    context.close();

But this example upload files to root directory. Thanks in advance.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
mlethys
  • 436
  • 9
  • 29

2 Answers2

1

I've just tested it and work well:

<int-ftp:outbound-channel-adapter
                id="sendFileToServer"
                auto-create-directory="true"
                session-factory="ftpSessionFactory"
                remote-directory="/Users/test"/>

Where my FTP server is an embedded one and its root is:

[MY_USER_HOME]\Temp\junit7944189423444999123\FtpServerOutboundTests\

So the file is stored in the dir:

[MY_USER_HOME]\Temp\junit7944189423444999123\FtpServerOutboundTests\Users\test\

It is with the latest Spring Integration version.

Which is your version?

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • My version is 2.1.6 But I'm not sure if I understand everything correctly. If I have, for example folder 'upload' in localhost server, I should in remote-directory give "/upload" right? Don't know why I thought that remote-directory specified path from witch I want to upload files. Correct me please if I'm wrong. – mlethys Jul 11 '14 at 11:18
  • Ok, I know what I was doing wrong. Thanks for answer. You really cleared that for me :) – mlethys Jul 11 '14 at 11:35
  • Oh! Good to know. You saved my time to explain it for you ;-) – Artem Bilan Jul 11 '14 at 11:35
1

Using FTPClient upload MultipartFiles to apache FTP server useful repo Hope this help for future search.