示例#1
0
        static void Main(string[] args)
        {
            string argOptionParamterSeperators = ":";

            foreach (string arg in args)
            {
                var argParts = arg.Trim().Split(argOptionParamterSeperators.ToCharArray(), 2);
                parseCommandLineArg(argParts[0].ToLower(), (argParts.Length > 1 ? argParts[1] : ""));
            }


            if (!ValidConfig)
            {
                return;
            }

            // Use a slight delay before continuing to ensure pipes are created by the myrtille.services
            Thread.Sleep(600);


            pipeMessaging = new PipeMessaging(RemoteSessionID);

            // Connect to myrtille input and update pipes
            if (pipeMessaging.CreateCommunicationPipes())
            {
                pipeMessaging.OnMessageReceivedEvent += PipeMessaging_OnMessageReceivedEvent;
                try
                {
                    // Read input from pipes
                    pipeMessaging.ReadInputPipes();
                }
                catch (Exception ex)
                {
                    if (ConsoleOutput)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                finally
                {
                    DisconnectSSHClient();
                }
            }
        }
示例#2
0
        private static int Main(string[] args)
        {
            // enable the code below for debug; disable otherwise
            //if (Environment.UserInteractive)
            //{
            //    MessageBox.Show("Attach the .NET debugger to the 'SSH Debug' Myrtille.SSH.exe process now for debug. Click OK when ready...", "SSH Debug");
            //}
            //else
            //{
            //    Thread.Sleep(10000);
            //}

            // logger
            XmlConfigurator.Configure();

            string argKeyValueSeparator = ":";

            foreach (string arg in args)
            {
                var argParts = arg.Trim().Split(argKeyValueSeparator.ToCharArray(), 2);
                parseCommandLineArg(argParts[0].ToLower(), (argParts.Length > 1 ? argParts[1] : ""));
            }

            if (!ValidConfig)
            {
                return((int)RemoteSessionExitCode.InvalidConfiguration);
            }

            pipeMessaging = new PipeMessaging(RemoteSessionID);

            if (pipeMessaging.ConnectPipes())
            {
                pipeMessaging.OnMessageReceivedEvent += PipeMessaging_OnMessageReceivedEvent;

                try
                {
                    pipeMessaging.ReadInputsPipe();
                }
                catch (Exception e)
                {
                    if (ConsoleOutput)
                    {
                        Console.WriteLine(e.Message);
                    }

                    Trace.TraceError("SSH error, remote session {0} ({1})", RemoteSessionID, e);

                    if (e is SshAuthenticationException)
                    {
                        if (e.Message == "Missing Username")
                        {
                            return((int)RemoteSessionExitCode.MissingUserName);
                        }
                        else if (e.Message == "Missing Password")
                        {
                            return((int)RemoteSessionExitCode.MissingPassword);
                        }
                        else
                        {
                            return((int)RemoteSessionExitCode.InvalidCredentials);
                        }
                    }

                    return((int)RemoteSessionExitCode.Unknown);
                }
                finally
                {
                    pipeMessaging.ClosePipes();
                    DisconnectSSHClient();
                }
            }

            return((int)RemoteSessionExitCode.Success);
        }