【问题标题】:I cant read file from ftp server, FTP Streaming Inbound Channel Adapter我无法从 ftp 服务器读取文件,FTP 流入站通道适配器
【发布时间】:2016-10-11 22:27:31
【问题描述】:

我想使用 FTP Streaming Channel Adapter 进行非常简单的示例,从 ftp 服务器读取文件,我阅读了文档,但我不清楚, 我设法将文件写入读取示例的 ftp 服务器,但是我无法以 InputStream 获取读取文件

<int:gateway service-interface="ftpmodule.service.FileWriterFTP"
    default-request-channel="ftpOutChannel"/>

<int-ftp:outbound-channel-adapter
    session-factory="ftpClientFactory" channel="ftpOutChannel"
    remote-directory="/web/" remote-filename-generator-expression="headers['fileName']">
</int-ftp:outbound-channel-adapter>

还有我的课

 public interface FileWriterFTP {

   public void write(@Header("fileName") String fileName,@Payload String message);

    public void write(@Header("fileName")String fileName,@Payload File file);
}

我运行应用程序,一切正常

public class AppConfig implements ApplicationRunner {

    @Autowired
    FileReaderFTP fileWriterFTP;
    public static void main(String[] args) {
        SpringApplication.run(AppConfig.class, args);
    }

    public void run(ApplicationArguments arg0) throws InterruptedException, ExecutionException, IOException {
        fileWriterFTP.write("test.txt","test");
    }
}

但我无法读取文件:

<int:channel id="ftpInChannel"/>

<int:gateway service-interface="ftpmodule.service.FileReaderFTP"
default-request-channel="ftpInChannel"/>

<int-ftp:inbound-streaming-channel-adapter session-factory="ftpClientFactory"
channel="ftpInChannel" filename-pattern="*.txt"
remote-file-separator="/" remote-directory="/web/">
</int-ftp:inbound-streaming-channel-adapter>

public interface FileReaderFTP {

    public InputStream read(String fileName);

}
@Autowired
FileReaderFTP fileReaderFTP;
InputStream stream = fileReaderFTP.read("test.txt");

【问题讨论】:

    标签: java spring ftp spring-integration


    【解决方案1】:

    您误解了入站通道适配器的工作方式 - 它是将输入流发送到通道的轮询适配器。

    对于您的场景,您需要使用带有流式 GET 命令的出站网关。

    the gateway documentation

    您还需要更多代码,因为对于流式传输请求,您负责关闭输入流所属的会话。

    【讨论】:

      猜你喜欢
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多