[英]Spring FTP issue when sending file TO FTP
I'm trying to send a file to a FTP. 我正在尝试将文件发送到FTP。
I noticed that using a command prompt everything is ok if I do this: 我注意到使用命令提示符,如果这样做,一切正常:
put test.txt 'MY_FILE_NAME_IN_FTP_HERE'
But, trying to send the file using my Spring I'm getting this: 但是,尝试使用Spring发送文件,我得到了:
exception is java.io.IOException: Failed to write to 'MY_FILE_NAME_IN_FTP_HERE'.
异常是java.io.IOException:无法写入“ MY_FILE_NAME_IN_FTP_HERE”。 Server replied with: 554 Requested action not taken: GDG name conversion failed.
服务器回复:554未采取请求的操作:GDG名称转换失败。
My handler is like (this is like the outbound channel adapter if you want to see this as a xml): 我的处理程序就像(如果您希望将其视为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;
}
My question is, why am I missing in my sessionFactory 我的问题是,为什么我的sessionFactory不见了
After having added ftpSessionFactory.setFileType(FTP.ASCII_FILE_TYPE);
添加
ftpSessionFactory.setFileType(FTP.ASCII_FILE_TYPE);
To my session Factory, the problem has gone. 在我的工厂会议上,问题已经解决了。
So My new Sessiong Factory config is: 因此,我的新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.