hi i am getting the below exception when trying to upload csv file to SFTP server using spring integration, not able to figure out what is happening wrong , but on the server i can see file like 10132_1234.csv.writing , but the writing opertaion never get complete ,whereas through winscp i am able to copy without any issue, please help to resolve this issue ,
Caused by: org.springframework.messaging.MessagingException: Failed
to write to 'file-location/10132_1234.csv.writing' while uploading
the file; nested exception is
org.springframework.core.NestedIOException: failed to write file;
nested exception is 3: Forbidden at
org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:560)
at
org.springframework.integration.file.remote.RemoteFileTemplate.doSend(RemoteFileTemplate.java:337)
... 88 common frames omitted`enter code here`
Caused by: org.springframework.core.NestedIOException: failed to
write file; nested exception is 3: Forbidden at
org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:177)
at
org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession.write(CachingSessionFactory.java:235)
at
org.springframework.integration.file.remote.RemoteFileTemplate.doSend(RemoteFileTemplate.java:568)
at
org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:557)
... 89 common frames omitted
Caused by: com.jcraft.jsch.SftpException: Forbidden at
com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:594) at
com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:540) at
com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:492) at
org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:174)
... 92 common frames omitted
Here is my upload code :
@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(sftpPort);
factory.setUser(sftpUser);
if (sftpPrivateKey != null) {
factory.setPrivateKey(sftpPrivateKey);
factory.setPrivateKeyPassphrase(sftpPrivateKeyPassphrase);
} else {
factory.setPassword(sftpPasword);
}
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<>(factory);
}
@Bean
@ServiceActivator(inputChannel = "toSftpChannel")
public MessageHandler handler() {
logger.info("Entering into MessageHandler for uploading the file to SFTP server");
SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
handler.setRemoteDirectoryExpression(new LiteralExpression(sftpRemoteDirectory));
handler.setFileNameGenerator(message -> {
if (message.getPayload() instanceof File) {
return ((File) message.getPayload()).getName();
} else {
throw new IllegalArgumentException("File expected as payload.");
}
});
return handler;
}
@MessagingGateway
public interface UploadGateway {
@Gateway(requestChannel = "toSftpChannel")
void upload(File file);
}
Just check whether you have provided valid file path as the destination . It should be the exact file path on what it writes the upstream file content
springframework.integration.sftp.session.SftpSession.write(InputStream inputStream, String destination)
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.