![](/img/trans.png)
[英]Sending Successful FTP File Upload Message with Spring Integration
[英]Spring FTP issue when sending file TO FTP
我正在尝试将文件发送到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不见了
添加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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.