- Forum posts: 1
Oct 31, 2016, 7:26:15 PM via Website
Oct 31, 2016 7:26:15 PM via Website
Hello Together,
I have a Problem by Programming a ssh connection between pc and android phone.
I already wrote the code and i ran it in eclipse and there it works.
Now i copy and pasted it into android studio and it is running with an error.
I am using Maverick SSH2 example code
The Problem : i use the command executeCommand("echo > help.txt") and in eclipse the programm sends the command and finishs.
In contrast to Android Studio, when i use executeCommand there it sends ("echo > help.txt"), too but still stays in executeCommand. All Commands after this wont be called. It stucks in the command.
Does anyone has an idea ?
I dont know what to do, i thought when it is running in eclipse it has to run in android studio as well.
Thanks for Help!
Fiixx
the Code:
import com.sshtools.net.SocketTransport;
import com.sshtools.ssh.ChannelOpenException;
import com.sshtools.ssh.PasswordAuthentication;
import com.sshtools.ssh.SshAuthentication;
import com.sshtools.ssh.SshClient;
import com.sshtools.ssh.SshConnector;
import com.sshtools.ssh.SshException;
import com.sshtools.ssh.SshSession;
import com.sshtools.util.IOStreamConnector;
import java.io.IOException;
/**
* Created by Zouca on 31.10.2016.
*/
class SSH implements Runnable {
@Override
public void run() {
//Code wich should be run
try {
SshConnector con = SshConnector.createInstance();
SshClient ssh;
ssh = con.connect(new SocketTransport("192......", 22),
"username");
PasswordAuthentication pwd = new PasswordAuthentication();
pwd.setPassword("password");
if(ssh.authenticate(pwd)== SshAuthentication.COMPLETE)
{System.out.println("Authentication succeeded");}
SshSession session = ssh.openSessionChannel();
session.executeCommand("echo > hello.txt");
}
catch (SshException | IOException | ChannelOpenException e) {
e.printStackTrace();
System.out.println("Authentication failed");
}
System.out.println("!!! I came to the End ! Never seen this at console !!");
}
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.