function: read the contents of files in the specified directory on the remote linux server.
known: server IP, port number, user name, password, path, file name.
I use ssh2 mode to establish a connection, and then I can only upload or retrieve files. The code is as follows:
Connection con = new Connection("IP");
ConnectionInfo connect = con.connect();
boolean isAuthed = con.authenticateWithPassword("", "");
SCPClient scpClient = con.createSCPClient();
//
scpClient.get("/home/test /a.txt", "C:/test/b.txt");
//
scpClient.put("C:/test/c.txt", "/home /test/d.txt");
then I queried and found that the Linux command could be executed through the session. The code is as follows:
Session session = con.openSession();
//
session.execCommand("mv -f /home/test/a.txt /home/test2/b.txt");
//
session.execCommand("scp root@192.168.1.1:/home/test/a.txt /home/test2/b.txt");
//
session.execCommand("scp /home/test2/b.txt root@192.168.1.1:/home/test/a.txt");
but I do not know how to read the file, because I just need to read the file, without downloading to the local case, read directly into memory to perform content processing, please give advice.
using the jar package is svnkit-1.9.0-r10609-atlassian-hosted.jar.
refer to the description of this blog, and on this basis, change some according to your own situation, which is roughly consistent with this description.
JAVA code implements file manipulation on remote servers-CSDN blog
https://blog.csdn.net/tao_ssh.