rogue-one
rogue-one

Reputation: 11587

Write to remote file using SSH

I want to write a String generated by a POJO to be written to a file in a remote server accessible only through scp/ssh. Would like to avoid creating local temporary file and scp the files to the remote machines. Implementation using Jsch library is preferred.

Upvotes: 0

Views: 3212

Answers (1)

rogue-one
rogue-one

Reputation: 11587

I followed @Kenster's recommendation and ended up doing something like below.

session = jsch.getSession(user, agent, port);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
((ChannelSftp) channel).put(new ByteArrayInputStream(args[0].getBytes()), args[1]);

Upvotes: 1

Related Questions