简体   繁体   中英

Spring FTP issue when sending file TO FTP

I'm trying to send a file to a 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:

exception is java.io.IOException: Failed to write to 'MY_FILE_NAME_IN_FTP_HERE'. Server replied with: 554 Requested action not taken: GDG name conversion failed.

My handler is like (this is like the outbound channel adapter if you want to see this as a 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

After having added ftpSessionFactory.setFileType(FTP.ASCII_FILE_TYPE); To my session Factory, the problem has gone.

So My new Sessiong Factory config is:

    @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);        
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM