On the difference between SCPClient class of ganymed-ssh2 version 262 and build210

ganymed-ssh2 is a tool library that uses SSH to connect to the server through java. The previous two versions of pom file configuration are as follows:
<!--ssh connect linux-->
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
<dependency>
   <groupId>ch.ethz.ganymed</groupId>
   <artifactId>ganymed-ssh2</artifactId>
   <version>build210</version>
</dependency>
<!--ssh connect linux-->
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
<dependency>
   <groupId>ch.ethz.ganymed</groupId>
   <artifactId>ganymed-ssh2</artifactId>
   <version>262</version>
</dependency>
Most people on the network use build210 version. I used 262 version before, but I didn't want to write my own file to upload and download the code. Instead, I used build210 version.
This is the method included in SCPClient of build210, including file download (get) and file upload (put). It is very convenient to call directly when using:


 

Compared with build210, SCPClient in version 262 lacks many methods and can only get files from the server. However, put method also needs to be used with other classes and cannot upload file server directly. It may be that the corresponding functions have been removed from other modules:

 

Here is build210 Upload and download cases:

public class ScpOpt {

    static String ip = "127.0.0.2";
    static String LiuxUser = "root";
    static String LiuxPawd = "xxxx";
public static void downloadFile() {
        Connection conn = new Connection(ip);
        Session session = null;// Open a session
        try {
            conn.connect();//Establish a connection
            boolean login = conn.authenticateWithPassword(LiuxUser, LiuxPawd);//Verify according to user name and password 
            if (login) {
                System.out.println("Login successful");
            } else {
                System.out.println("Login failed");
            }
            SCPClient scpClient = conn.createSCPClient();
            //Get files from remote machine
            scpClient.get("Remote files/root/docker-install.sh", "Local folder");
            conn.close();
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void uploadFile() {
        Connection conn = new Connection(ip);
        try {
//Establish a connection conn.connect();
//Verify according to user name and password

boolean login = conn.authenticateWithPassword(LiuxUser, LiuxPawd); if (login) { System.out.println("Login successful"); } else { System.out.println("Login failed"); } SCPClient scpClient = conn.createSCPClient();
//Upload file scpClient.put(
"Local file docker-install.sh", "Remote machine directory/root/scp"); conn.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { // downloadFile(); uploadFile(); } }

Tags: Session ssh Linux Docker

Posted on Wed, 27 May 2020 10:40:53 -0400 by kharbat