private void FindAccessGrantedMessage(string text)
        {
            if (text.Contains(@"Access granted"))
            {
                if (this.Info.AuthType == AuthenticationType.PrivateKey)
                {
                    PrivateKeyStorage.Delete(this.Info.PrivateKeyData);
                }

                this.PublishMessage(
                    MessageSeverity.Debug,
                    string.Format("Access granted called: {0}", this.Info.DisplayText));

                var shellWontBeStarted = string.IsNullOrWhiteSpace(this.Info.RemoteCommand);
                if (shellWontBeStarted)
                {
                    this.timer = new Timer(
                        delegate
                    {
                        this.PublishMessage(
                            MessageSeverity.Debug,
                            string.Format("Delegate called: {0}", this.Info.DisplayText));
                        this.State = ConnectionState.Open;
                    },
                        null,
                        1500,
                        Timeout.Infinite);
                }
            }
        }
        public void Close()
        {
            if (this.State == ConnectionState.Closed)
            {
                return;
            }

            this.CheckConsistency();

            if (this.Info.AuthType == AuthenticationType.PrivateKey)
            {
                PrivateKeyStorage.Delete(this.Info.PrivateKeyData);
            }

            try
            {
                if (!this.process.HasExited)
                {
                    this.State = ConnectionState.Closing;
                    this.process.Kill();
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
            }

            this.State = ConnectionState.Closed;
        }
Пример #3
0
        public void StartPsftp(ConnectionInfo connectionInfo)
        {
            var fileName = Path.Combine(PathHelper.StartupPath, PsftpLocation);
            var args     = ArgumentsBuilder.BuildPsftpArguments(
                connectionInfo,
                PrivateKeyStorage.Create(connectionInfo.PrivateKeyData).Filename);

            Process.Start(fileName, args);
        }
        public void Open()
        {
            try
            {
                this.CheckConsistency();

                this.passwordProvided         = false;
                this.passphraseForKeyProvided = false;
                this.HasForwardingFailures    = false;
                this.State = ConnectionState.Opening;
                this.multilineErrorText.Clear();

                string privateKeyFileName = null;
                if (this.Info.AuthType == AuthenticationType.PrivateKey)
                {
                    privateKeyFileName = PrivateKeyStorage.Create(this.Info.PrivateKeyData).Filename;
                }

                var puttyArguments = ArgumentsBuilder.BuildPuttyArguments(this.Info, false, privateKeyFileName);
                this.process = new Process
                {
                    StartInfo =
                    {
                        FileName               = PLinkLocation,
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardInput  = true,
                        Arguments              = puttyArguments
                    }
                };

                this.process.Exited             += (s, a) => this.Close();
                this.process.ErrorDataReceived  += this.HandleErrorData;
                this.process.OutputDataReceived += this.HandleOutputData;
                this.process.Start();
                this.process.BeginErrorReadLine();
                this.process.BeginOutputReadLine();

                this.process.StandardInput.AutoFlush = true;
            }
            catch (Exception ex)
            {
                this.PublishFatalError(ex.Message);
                this.Close();
            }
        }