android - Android 上使用 JSCH 的 SSH 连接、UnknownHostException

标签 android ssh jsch

我正在尝试使用 JSCH 通过 SSH 连接到我的服务器。

JSch jsch = new JSch();
    jsch.setConfig("StrictHostKeyChecking", "no");
    session = jsch.getSession(this.username, this.host, 22);
    session.setPassword(this.password);
    Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    this.session.connect();

错误到达最后一行的 session.connect

12-10 00:21:35.696: W/System.err(30732): com.jcraft.jsch.JSchException: java.net.UnknownHostException: Unable to resolve host "android.widget.EditText{4257c438 VFED..CL .F....ID 219,0-849,117 #7f080008 app:id/host}": No address associated with hostname

我可以使用 Google ConnectBot 成功访问我的服务器,但不是这样...

这是我的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />

<application
    android:debuggable="true"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
      android:name="com.exemple.myapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    />
</manifest>

预先感谢您的帮助!

最佳答案

如果 this.host 是编辑文本,则必须在 jsch.getSession() 中调用 this.host.getText().toString()。如果用户名和密码也是编辑文本对象,则同样如此。

关于android - Android 上使用 JSCH 的 SSH 连接、UnknownHostException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20483064/

相关文章:

android - 与滑动 RecyclerView 协调的折叠/展开 View

python - 使用 SSH 隧道让 Django 服务器认为它在 AWS 中运行?

Git克隆产生错误的数据包长度错误

java - 如何通过 Ant build.xml 文件将 war 文件发送到 Windows 机器位置

java - JSch Esc 命令和编码

java - Libgdx:用于碰撞的平铺对象层

android - 默认 Android 12 相机,对所有文件没有访问管理 ResultCode 始终为 0

Android nfcA.connect()、nfcA.transceive()、nfcA.setTimeout() 和 nfcA.getMaxTransceiveLength()

bash - 转义单引号 ssh 远程命令

ssh - sftp 失败,错误为 'message too long'