【问题标题】:Uploading files directly to specific folder in ftp server using spring spring使用spring spring将文件直接上传到ftp服务器中的特定文件夹
【发布时间】:2014-07-11 09:37:44
【问题描述】:

我想,我有一个非常新手的问题,但事实是我是 Spring 框架的新手。 如何将文件上传到我的 ftp 服务器根目录中的“上传”文件夹? 我试过这个: 我的应用程序上下文文件:

<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"/>

还有我的java代码:

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();

但是这个例子上传文件到根目录。 提前致谢。

【问题讨论】:

    标签: ftp spring-integration


    【解决方案1】:

    我刚刚测试过并且运行良好:

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

    我的 FTP 服务器是嵌入式的,它的根是:

    [MY_USER_HOME]\Temp\junit7944189423444999123\FtpServerOutboundTests\
    

    所以文件存放在目录中:

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

    它是最新的 Spring Integration 版本。

    你的版本是什么?

    【讨论】:

    • 我的版本是 2.1.6 但我不确定我是否理解正确。例如,如果我在本地主机服务器中有文件夹“上传”,我应该在远程目录中提供“/上传”对吗?不知道为什么我认为远程目录指定了我要上传文件的女巫的路径。如果我错了,请纠正我。
    • 好的,我知道我做错了什么。感谢您的回答。你真的为我清除了:)
    • 哦!很高兴知道。你节省了我为你解释的时间;-)
    【解决方案2】:

    使用 FTPClient 上传 MultipartFiles 到 apache FTP 服务器 useful repo 希望这对将来的搜索有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-09
      • 2012-10-04
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多