简体   繁体   中英

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.

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]);

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