Results 1 to 1 of 1
- 08-03-2011, 11:51 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
SSH Connection with host linux "ganymed"
hi
I must connect with a linux host via ssh.
I found the library "Ganymed", it seemed to work but I saw that some commands do not give me the desired result.
For example, I tried to run the following commands
"pwd"
"cd .."
"pwd"
the output of the first command is the same as the third.
This is the basic code for the ssh connection
Java Code:String hostname = "127.0.0.1"; String username = "joe"; String password = "joespass"; try { /* Create a connection instance */ Connection conn = new Connection(hostname); /* Now connect */ conn.connect(); boolean isAuthenticated = conn.authenticateWithPassword(username, password); if (isAuthenticated == false) throw new IOException("Authentication failed."); /* Create a session */ Session sess = conn.openSession(); sess.execCommand("uname -a && date && uptime && who"); System.out.println("Here is some information about the remote host:"); InputStream stdout = new StreamGobbler(sess.getStdout()); BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); while (true) { String line = br.readLine(); if (line == null) break; System.out.println(line); } /* Show exit status, if available (otherwise "null") */ System.out.println("ExitCode: " + sess.getExitStatus()); /* Close this session */ sess.close(); /* Close the connection */ conn.close(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(2); }
In jar file of the library I found other examples, that creates a shell using swing.
In this example the comand go well.
Someone knows how to solve my problem?
You know other library that can I use?
Before "Ganymed" I tried "jsch" library and I have the same problem.
Thank you in advance for you answer
Similar Threads
-
how do I install windows"javac" jdk to usb drive using linux (ubuntu)
By rhythmiccycle in forum New To JavaReplies: 0Last Post: 01-04-2011, 07:44 PM -
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 04:21 PM -
"Could not find the main class" for Linux Command Line Compile
By tetelee in forum New To JavaReplies: 3Last Post: 08-25-2010, 10:21 AM -
Java Mail "SMTP host" Exception
By Poyntz in forum NetworkingReplies: 15Last Post: 01-06-2009, 07:52 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks