简体   繁体   English

使用SSH写入远程文件

[英]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. 我想写一个由POJO生成的字符串,以将其写入只能通过scp / ssh访问的远程服务器中的文件。 Would like to avoid creating local temporary file and scp the files to the remote machines. 想要避免创建本地临时文件并将文件scp到远程计算机。 Implementation using Jsch library is preferred. 使用Jsch库的实现是首选。

I followed @Kenster's recommendation and ended up doing something like below. 我遵循@Kenster的建议,最终做了如下所示的事情。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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