Switch to unified view

a b/src/test/java/net/timbusproject/extractors/util/SSHManagerTest.java
1
package net.timbusproject.extractors.util;
2
3
import com.jcraft.jsch.Session;
4
import net.timbusproject.extractors.modules.tavernaextractor.utils.SSHManager;
5
import org.junit.Test;
6
7
import java.io.File;
8
9
public class SSHManagerTest{
10
11
12
    @Test
13
    public void test_communication()throws Exception{
14
15
        SSHManager ssh = new SSHManager("172.16.1.42",22, "timbus", "timbus");
16
        Session session = ssh.createSession(60000);
17
18
        // downloading file
19
        File file = ssh.readFile(session, "/home/timbus/Documents/opencv.sh");
20
        if(file!=null){
21
            System.out.println("File successfully saved at "+file.getAbsolutePath() + " [size="+file.length()+"]");
22
        }
23
24
        while(session.isConnected()){
25
            ;
26
        }
27
28
        // receiving file
29
30
        /*
31
          IMPORTANT: session.disconnect sends session object into the void.
32
          Therefore it is necessary to create a new session after a sessions.disconnect() call.
33
         */
34
        session = ssh.createSession(60000);
35
        ssh.sendFile(session, file.getAbsolutePath(), "/home/timbus/Documents/opencv.sh.new");
36
        System.out.println("Send file to /home/timbus/Documents/opencv.sh.new has been executed without errors.");
37
    }
38
}