Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tydero · Jun 06, 2015 at 04:19 PM · c#connectionsecuritycompilationafter

Using a SSH connection in a Unity project

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\n";
 
             using (var client = new SshClient(connectionInfo ))
             {
                 text.text += "Connecting...\n";
                 client.Connect();
                 text.text += "OK\n";
                 
                 var command = client.RunCommand("pwd");
                 text.text += command.Result;
                 
                 text.text += "Disconnecting...\n";
                 client.Disconnect();
                 text.text += "OK\n";
 
                 Debug.Log (text.text);
             }
         }
         catch(System.Exception e)
         {
             text.text = "Error\n" + 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 ?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xaverix · Jun 08, 2015 at 03:36 PM 0
Share

How did you add that library to Unity3d?

avatar image Tydero · Jun 08, 2015 at 04:34 PM 0
Share

Drag & drop into /Assets/Plugins

edit : use directly the 3.5 .NET dll

avatar image Xaverix · Jun 08, 2015 at 04:40 PM 0
Share

I have some errors :/

avatar image bartoszczybartlomiej · Jul 23, 2015 at 09:04 AM 0
Share

HI,

I tried to test your script on android device and I have same problem. Script working perfectly in Unity Editor but on android device I have same error message. I don't have idea to how to solve this problem ;/

alt text

screenshot-2015-07-22-21-27-49.png (151.3 kB)
avatar image jtrue · Oct 01, 2016 at 02:30 AM 0
Share

I am trying to install this library in Unity on my mac. I am deploying onto iOS. I would like more info on how this library is installed. Where do i get the 3.5 .NET dll?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Packetstorm · Jul 13, 2015 at 05:48 AM

Hi Tydero, i used your code and it worked for me, maybe check that you can connect via something like putty first. the only error i get is "Line has invalid autocommand "pwd"Disconnecting..." wondering if you may know what this is because it seems to happen after the authentication.

maybe we can help each other to get it working as i need it for one of my projects as well

Hi Tydero, its ok, maybe someone else will see this and be able to shed some light on it, when i use "var x = client.RunCommand("known command");" i get the below error. did some searching and someone said that it may be a part of unity's security that is blocking me but i am unsure. basically i wand to use either telnet or ssh (preferably ssh) to view lets call them logs from a local ip address. i will then filter the data and only show the parts with the tags that i need. if anyone has any ideas i am open to them.

Error System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine.

at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in :0 at Renci.SshNet.Session.SocketWrite (System.Byte[] data) [0x00000] in :0 System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tydero · Jul 13, 2015 at 11:06 PM 0
Share

Hello,

Putty was working fine. I stopped using ssh since i didn't manage to get it working soon enough. I m sorry, but i cant really help you.

Did you try another simple command like "ls" (UNIX) / "dir" (WINDOWS) ? $$anonymous$$aybe put a ending-line symbol at the end ("\n" or "\r\n") ?

If you find a way to get it working, it would be great if you post it there, because if remember well, i was on the first page of google not long after i asked this ...

Good luck on get it working !

avatar image
0

Answer by gfxguru · May 12, 2016 at 02:49 PM

@Tydero @Packetstorm I was able to make it work by using .NET 2.0 instead of .NET 2.0 subset. I had some compilation when stripping was enabled , disable stripping also if you have any problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

ECDiffieHellmanCng missing from unity? 1 Answer

A way to execute code on editor launch but not on scripts recompilation 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges