![](/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.