Exemple #1
0
        protected override bool HandleOnExit(ref bool isError)
        {
            if (_restart)
            {
                Retry();
                return(true);
            }

            // An error occurred!
            if (isError && Plink)
            {
                var output = GetOutputString();

                // there might be another error, this condition is too weak

                /*
                 * if (output.Contains("successfully authenticated"))
                 * {
                 *  isError = false;
                 *  return false;
                 * }
                 */

                // If the authentication failed because of a missing key, ask the user to supply one.
                if (output.Contains("FATAL ERROR") && output.Contains("authentication"))
                {
                    if (FormPuttyError.AskForKey(this, out var loadedKey))
                    {
                        // To prevent future authentication errors, save this key for this remote.
                        if (!string.IsNullOrEmpty(loadedKey) && !string.IsNullOrEmpty(Remote) &&
                            string.IsNullOrEmpty(Module.GetSetting("remote.{0}.puttykeyfile")))
                        {
                            Module.SetPathSetting(string.Format("remote.{0}.puttykeyfile", Remote), loadedKey);
                        }

                        // Retry the command.
                        Retry();
                        return(true);
                    }
                }

                if (output.Contains("the server's host key is not cached in the registry", StringComparison.OrdinalIgnoreCase))
                {
                    string remoteUrl;

                    if (string.IsNullOrEmpty(_urlTryingToConnect))
                    {
                        remoteUrl = Module.GetSetting(string.Format(SettingKeyString.RemoteUrl, Remote));
                        if (string.IsNullOrEmpty(remoteUrl))
                        {
                            remoteUrl = Remote;
                        }
                    }
                    else
                    {
                        remoteUrl = _urlTryingToConnect;
                    }

                    if (AskForCacheHostkey(this, Module, remoteUrl))
                    {
                        Retry();
                        return(true);
                    }
                }
            }

            return(base.HandleOnExit(ref isError));
        }