Exemple #1
0
        public virtual string CloseConsole(UserGameParam param, string closeCommand = "")
        {
            var run = $"^b d";

            if (Terminal == null || Writer == StreamWriter.Null)
            {
                return("");
            }
            Writer?.WriteLine(run);
            FoundConsoleEnd        = null;
            Terminal.DataReceived += Terminal_DataReceived;
            Writer?.Close(); Writer?.Dispose(); Writer = StreamWriter.Null;
            Terminal?.Close(); Terminal?.Dispose();
            return(CollectResiveString);
        }
 public void Dispose()
 {
     _shell?.Dispose();
     _shell?.Close();
     _sshClient?.Disconnect();
     _sshClient?.Dispose();
 }
Exemple #3
0
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool Disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (Disposing)
            {
                // Free any other managed objects here.

                if (Stream != null)
                {
                    Stream.Dispose();
                    Stream = null;
                }

                if (OwnClient && Client != null)
                {
                    Client.Disconnect();
                    Client.Dispose();
                    Client = null;
                }
            }

            // Free any unmanaged objects here.

            Disposed = true;
        }
Exemple #4
0
    private bool disposedValue = false;     // To detect redundant calls

    protected virtual void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                // prevent double dispose
                // don't dispose of sr or sw: only disposable resource is ssh
                ssh.Dispose();
            }

            disposedValue = true;
        }
    }
    private async Task CloseSocket(WebSocket socket)
    {
        await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", new CancellationToken());

        socket.Dispose();
        WebSocket dummy;

        _sockets.TryRemove(GetId(socket), out dummy);
        _stream.Dispose();
        _stream = null;
        _client.Disconnect();
        _client.Dispose();
        _client = null;
    }
Exemple #6
0
    private bool disposedValue = false;     // To detect redundant calls

    protected virtual void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                sw.Dispose();
                sr.Dispose();
                ssh.Dispose();
            }

            disposedValue = true;
        }
    }
 /// <inheritdoc />
 public void Dispose()
 {
     try
     {
         ShellStream?.Dispose();
         ShellStream = null;
         SshClient?.Dispose();
         SshClient = null;
         Lines.Dispose();
     }
     catch
     {
         //
     }
 }
Exemple #8
0
        public string RunShell(string command)
        {
            string result = string.Empty;

            try
            {
                using (var client = new SshClient(this.host, this.username, this.password))
                {
                    client.Connect();
                    IDictionary <Renci.SshNet.Common.TerminalModes, uint> termkvp = new Dictionary <Renci.SshNet.Common.TerminalModes, uint>();
                    termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);

                    ShellStream shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp);

                    StreamReader reader = new StreamReader(shellStream);
                    StreamWriter writer = new StreamWriter(shellStream);
                    writer.AutoFlush = true;

                    result += reader.ReadToEnd();
                    while (shellStream.Length == 0)
                    {
                        Thread.Sleep(500);
                    }

                    Thread.Sleep(500);
                    result += reader.ReadToEnd();

                    writer.WriteLine(command);
                    while (shellStream.Length == 0)
                    {
                        Thread.Sleep(500);
                    }

                    Thread.Sleep(1000);
                    result += reader.ReadToEnd();

                    shellStream.Dispose();
                    client.Disconnect();
                    client.Dispose();
                }
            }
            catch (Exception exc)
            {
                if (exc.ToString().Contains("No suitable authentication method found to complete authentication"))
                {
                    KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(this.username);
                    keybAuth.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent);
                    var connectionInfo = new ConnectionInfo(this.host, 22, this.username, keybAuth);
                    using (var client = new SshClient(connectionInfo))
                    {
                        client.Connect();
                        IDictionary <Renci.SshNet.Common.TerminalModes, uint> termkvp = new Dictionary <Renci.SshNet.Common.TerminalModes, uint>();
                        termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);

                        ShellStream shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp);

                        StreamReader reader = new StreamReader(shellStream);
                        StreamWriter writer = new StreamWriter(shellStream);
                        writer.AutoFlush = true;

                        result += reader.ReadToEnd();
                        while (shellStream.Length == 0)
                        {
                            Thread.Sleep(500);
                        }

                        Thread.Sleep(500);
                        result += reader.ReadToEnd();

                        writer.WriteLine(command);
                        while (shellStream.Length == 0)
                        {
                            Thread.Sleep(500);
                        }

                        Thread.Sleep(1000);
                        result += reader.ReadToEnd();

                        shellStream.Dispose();
                        client.Disconnect();
                        client.Dispose();
                    }
                }
            }
            return(result);
        }
Exemple #9
0
 public void Dispose()
 {
     sshStream.Dispose();
     client.Disconnect();
     client.Dispose();
 }