Search Unity

Renci.SshNet.Sftp iOS iPad - Connection Error

Discussion in 'iOS and tvOS' started by MotionBrain, Apr 11, 2021.

  1. MotionBrain

    MotionBrain

    Joined:
    Dec 5, 2015
    Posts:
    35
    I've a problem while connecting with a sftp - Server with my iPad iOS 14.4.1.

    I'm using the Renci.SshNet.Sftp Framework. On Mac Osx or Windows everything works perfectly. But on iPad its stops working at "sshClient.Connect();" I put the private key file into the StreamingAssets Folder.

    I'm using port 22. The server does not get any connection try.

    Code (CSharp):
    1. public void DownloadDirectory()
    2.     {
    3.         Renci.SshNet.ConnectionInfo conn =
    4.     new ConnectionInfo(hostName, port, username, new AuthenticationMethod[]
    5.         {
    6.          
    7.         new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[]
    8.                { new PrivateKeyFile(Application.streamingAssetsPath + "/privatekeyFile", "") }),
    9.         });
    10.         try
    11.         {
    12.             using (var sshClient = new SftpClient(conn))
    13.             {
    14.                 sshClient.Connect();
    15.                 var files = sshClient.ListDirectory(directory);
    16.                 foreach (var file in files)
    17.                 {
    18.                     if (!file.Name.StartsWith(".") && file.Name.StartsWith(localFileName))
    19.                     {
    20.                         string remoteFileName = file.Name;
    21.                         using (Stream file1 = File.OpenWrite(Application.streamingAssetsPath + localFileName))
    22.                         {
    23.                             Debug.Log(directory + remoteFileName);
    24.                             sshClient.DownloadFile(directory + remoteFileName, file1);
    25.                         }
    26.                     }
    27.                 }
    28.             }
    29.         }
    30.         catch (Renci.SshNet.Common.SshConnectionException)
    31.         {
    32.             Debug.LogError("Cannot connect to the server.");
    33.         }
    34.         catch (System.Net.Sockets.SocketException)
    35.         {
    36.             Debug.LogError("Unable to establish the socket.");
    37.         }
    38.         catch (Renci.SshNet.Common.SshAuthenticationException)
    39.         {
    40.             Debug.LogError("Authentication of SSH session failed.");
    41.         }
    42.     }
    43.  
    Error Message from Xcode.

    Code (CSharp):
    1. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    2.  
    3.     NullReferenceException: Object reference not set to an instance of an object.
    4.       at System.Linq.Expressions.Interpreter.LightLambda.MakeRunDelegateCtor (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0
    5.       at System.Linq.Expressions.Interpreter.LightLambda.GetRunDelegateCtor (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0
    6.       at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0
    7.       at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) [0x00000] in <00000000000000000000000000000000>:0
    8.       at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in <00000000000000000000000000000000>:0
    9.       at System.Linq.Expressions.Expression`1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in <00000000000000000000000000000000>:0
    10.       at System.Linq.Expressions.Expression`1[TDelegate].Compile () [0x00000] in <00000000000000000000000000000000>:0
    11.       at System.Runtime.CompilerServices.CallSite`1[T].CreateCustomNoMatchDelegate (System.Reflection.MethodInfo invoke) [0x00000] in <00000000000000000000000000000000>:0
    12.       at System.Runtime.CompilerServices.CallSite`1[T].MakeUpdateDelegate () [0x00000] in <00000000000000000000000000000000>:0
    13.       at System.Runtime.CompilerServices.CallSite`1[T].GetUpdateDelegate (T& addr) [0x00000] in <00000000000000000000000000000000>:0
    14.       at System.Runtime.CompilerServices.CallSite`1[T].GetUpdateDelegate () [0x00000] in <00000000000000000000000000000000>:0
    15.       at System.Runtime.CompilerServices.CallSite`1[T]..ctor (System.Runtime.CompilerServices.CallSiteBinder binder) [0x00000] in <00000000000000000000000000000000>:0
    16.       at System.Runtime.CompilerServices.CallSite`1[T].Create (System.Runtime.CompilerServices.CallSiteBinder binder) [0x00000] in <00000000000000000000000000000000>:0
    17.       at Renci.SshNet.Session.HandleMessageCore (Renci.SshNet.Messages.Message message) [0x00000] in <00000000000000000000000000000000>:0
    18.       at Renci.SshNet.Session.MessageListener () [0x00000] in <00000000000000000000000000000000>:0
    19.       at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    20.       at Renci.SshNet.Abstractions.ThreadAbstraction+<>c__DisplayClass1_0.<ExecuteThread>b__0 (System.Object o) [0x00000] in <00000000000000000000000000000000>:0
    21.       at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    22.       at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    23.       at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    24.       at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    25.       at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    26.       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0
    27.       at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0
    28.       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0
    29.  
    30.     (Filename: currently not available on il2cpp Line: -1)
    Hope you can help me.
    Is Renci.sshnet supporting iOS devices ?

    Regards

    MotionBrain