Java reads remote server files

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.

Mar.02,2021

get is an overloaded method, and the following function get (String remoteFile, OutputStream target)

is provided in the library.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
scpClient.get("/home/test /a.txt", baos);

// baos.toByteArray(); // 
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); // 
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9721b-1630.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9721b-1630.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?