how to create an file in remote directory from byte[], as there is send() methods available in PollableChannel. from below code able to send file to remote, but it's creating an file in local machine. how to avoid creating file in local machine?
PollableChannel remoteFileChannel = context.getBean("outputChannel", PollableChannel.class);
Message<byte[]> sendFile = MessageBuilder.withPayload("hi how are you".getBytes()).build();
remoteFileChannel.send(sendFile);
spring sftp configuration:
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"
p:host="${sftp.host}"
p:port="${sftp.port}"
p:user="${sftp.username}"
p:password="${sftp.password}"
p:allowUnknownKeys="${sftp.allowUnknownKeys}" />
<int:channel id="outputChannel">
<int:queue />
</int:channel>
<int-sftp:outbound-channel-adapter id="outboundAdapter"
session-factory="sftpSessionFactory"
channel="outputChannel"
charset="UTF-8"
remote-directory="${sftp.remotedir}"
remote-filename-generator="randomFileNameGenerator" />
how to create an file with random name and write bytes into it?
I have tried with custom file name generator class:
@Component("randomFileNameGenerator")
public class RandomFileNameGenerator implements FileNameGenerator {
@Override
public String generateFileName(Message<?> msg) {
long number = (long) Math.floor(Math.random() * 90000000L) + 1000000L;
String fileName = String.format("%d.txt", number);
return fileName;
}
}
where the filename was not setting, creating file with name like "adas-asdfsadf-545sadf.msg". can any one point me where am doing wrong