【问题标题】:Spring FTP issue when sending file TO FTP将文件发送到 FTP 时出现 Spring FTP 问题
【发布时间】:2017-03-14 18:25:31
【问题描述】:

我正在尝试将文件发送到 FTP。

我注意到,如果我这样做,使用命令提示符一切正常:

put test.txt 'MY_FILE_NAME_IN_FTP_HERE'

但是,尝试使用我的 Spring 发送文件时,我得到了这个:

异常是 java.io.IOException:无法写入“MY_FILE_NAME_IN_FTP_HERE”。服务器回复:554 未采取请求的操作:GDG 名称转换失败。

我的处理程序是这样的(如果您想将其视为 xml,这就像出站通道适配器):

@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
@ServiceActivator(inputChannel = "toFtpChannel")
public MessageHandler handler() throws IOException {
    FileTransferringMessageHandler handler = new FileTransferringMessageHandler(ftpSessionFactory());        

    final String fileNameExpression = MY_FILE_NAME_IN_FTP_HERE
    //TODO: Need to check how should be the actual remote directory expression. It is mandatory in the SessionFactory.
    handler.setRemoteDirectoryExpression(new LiteralExpression(""));        
    handler.setUseTemporaryFileName(false);
    handler.setFileNameGenerator(new FileNameGenerator() {
        public String generateFileName(Message<?> message) {
             return fileNameExpression;
        }
    });
    return handler;
}  

我的问题是,为什么我的 sessionFactory 不见了

【问题讨论】:

  • 尝试使用 `handler.setRemoteDirectoryExpression(new LiteralExpression("/"));` 或适合您的用户的内容。你的远程目录确实有问题:www-01.ibm.com/support/docview.wss?uid=swg21541374
  • 我已经尝试过使用(“/”)。我试图弄清楚为什么命令提示符可以正常工作,但 Spring 和 Filezilla 却不行(例如)。
  • 比较那里的workingDirectory。您的提示可能会选择不同的目录,而不是默认为您的用户选择的目录。

标签: java spring ftp spring-integration spring-integration-sftp


【解决方案1】:

ftpSessionFactory.setFileType(FTP.ASCII_FILE_TYPE); 添加到我的会话工厂后,问题就消失了。

所以我的新 Sessiong Factory 配置是:

    @Bean
public SessionFactory<FTPFile> ftpSessionFactory() throws IOException {
    DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();

    ftpSessionFactory.setHost(host);
    ftpSessionFactory.setPort(Integer.parseInt(port));
    ftpSessionFactory.setUsername(username);
    ftpSessionFactory.setPassword(password);
    ftpSessionFactory.setFileType(FTP.ASCII_FILE_TYPE);
    return new CachingSessionFactory<FTPFile>(ftpSessionFactory);        
}  

【讨论】:

    猜你喜欢
    • 2016-05-31
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    相关资源
    最近更新 更多