首先我不知道我是否正确集成了lib。
清单中我设置了Internet权限,并设置了权限:
compile 'com.jcraft:jsch:0.1.51'
compile 'org.bouncycastle:bcprov-jdk16:1.46'
班级管理员:
public class admin extends Activity {
关于简历:
@Override
public void onResume() {
super.onResume();
new AsyncTask<Integer, Void, Void>(){
@Override
protected Void doInBackground(Integer... params) {
try {
executeRemoteCommand();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute(1);
}
进行连接的方法和方法:
public void executeRemoteCommand()
{
final String fileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + PRIVATE_KEY_LOCATION;
File file = new File(fileName);
String hostname = "104.150.65.150";
String username = "testerbytes";
String keyfilePass = " "; // will be ignored if not needed
Session session;
JSch jsch;
try {
jsch = new JSch();
jsch.addIdentity(fileName);
session = jsch.getSession("testerbytes", "104.150.65.150", 22);
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("PreferredAuthentications", "publickey");
session.setConfig(prop);
session.connect();
if(session.isConnected()){
stOut.setText("Connected \n");
}else{
stOut.setText("NOT Connected \n");
}
}catch (Exception e){
e.printStackTrace();
}
}
stOut是在oncreate中声明的TextView,可以完美地被Toast取代...我将尝试建立与gcloud VM的ssh连接(我正确生成了私钥和公钥,并且可以与腻子和filezilla完美配合)
当我尝试在logcat上启动活动时,我收到以下信息:
在此处输入图片描述](https://i.stack.imgur.com/QGNUL.jpg)(发布图片需要至少10个信誉。...)
问题是我如何以正确的方式将JSCH库与我的android项目集成,以及如何通过我的ppk密钥文件与gcloud VM连接(我知道的ppk也与jsch lib兼容)
欢呼和感谢