Hello everyone,
I m trying to use SSH in a Unity project as i need a secured connection to an other server than the one hosting my project. This second server is not mine and this connection would allow me to call some bash scripts created and maintain by its owner.
I found two libraries : SharpSSH and SSH.NET
I didn’t manage to get the first one working so i wont talk about it.
The second one provides a 3.5 .NET dll (as Unity don’t work with 4.0), a good documentation and is easy to use.
It works perfectly in the development environment of Unity, but no longer after compilation. My goal is a web player client, but i also tried to compile it as a standalone build on windows, with the same result.
So I created a new project, with only a UI.Text in it and this script attached :
using UnityEngine;
using Renci.SshNet;
public class sshconnection : MonoBehaviour
{
private UnityEngine.UI.Text text = null;
private string _host = "host.h";
private string _username = "login";
private string _password = "password";
void Start()
{
text = this.GetComponent<UnityEngine.UI.Text> ();
try
{
var connectionInfo = new PasswordConnectionInfo(_host, 22, _username, _password);
text.text += "connection infos : ok
";
using (var client = new SshClient(connectionInfo ))
{
text.text += "Connecting...
";
client.Connect();
text.text += "OK
";
var command = client.RunCommand("pwd");
text.text += command.Result;
text.text += "Disconnecting...
";
client.Disconnect();
text.text += "OK
";
Debug.Log (text.text);
}
}
catch(System.Exception e)
{
text.text = "Error
" + e;
Debug.Log(text.text + e);
}
}
}
Of course the expected result would be an unknown host exception. In the following screenshot, the first error is in french even if i don’t know why, it’s written “Hôte inconnu” wich means “unknown host”.
Here’s the results :
http://imgur.com/a/leNqY
So i have two questions :
What am I missing to get this working ?
Should i reconsider using ssh for whatever reasons ?