Parent: [8d1358] (diff)

Download this file

SSHManagerTest.java    38 lines (29 with data), 1.3 kB

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