コード例 #1
0
        public String Format(IHostPwEntry hostPwEntry)
        {
            PuttyOptions options = null;
            bool         success = PuttyOptions.TryParse(hostPwEntry.AdditionalOptions, out options);

            StringBuilder sb = new StringBuilder(String.Format("\"{0}\" scp://{1}", ExecutablePath, hostPwEntry.GetUsername()));

            if (!success || (success && !options.HasKeyFile()))
            {
                sb.AppendFormat(":\"{0}\"", hostPwEntry.GetPassword());
            }

            sb.AppendFormat("@{0}", hostPwEntry.IPAddress);

            if (success && options.Port.HasValue)
            {
                sb.AppendFormat(":{0}", options.Port);
            }

            // Starting with version 5.6 a passphrase for the private key file can be provided.
            // See: https://winscp.net/eng/docs/faq_passphrase
            if (success && options.HasKeyFile())
            {
                sb.AppendFormat(" -privatekey=\"{0}\" -passphrase=\"{1}\"", options.KeyFilePath, hostPwEntry.GetPassword());
            }

            return(sb.ToString());
        }
コード例 #2
0
 public void ChangePassword(IHostPwEntry hostPwEntry, string newPassword)
 {
     this.passwordChanger.ChangePassword(
         hostPwEntry.IPAddress,
         hostPwEntry.GetUsername(),
         hostPwEntry.GetPassword(),
         newPassword
         );
 }
コード例 #3
0
        public string Format(IHostPwEntry hostPwEntry)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("\"{0}\"", this.ExecutablePath);
            sb.AppendFormat(" -s {0} -u {1} -p {2}",
                            hostPwEntry.IPAddress,
                            hostPwEntry.GetUsername(),
                            hostPwEntry.GetPassword()
                            );
            return(sb.ToString());
        }
コード例 #4
0
        public string Format(IHostPwEntry hostPwEntry)
        {
            StringBuilder sb = new StringBuilder();

            if (this.IncludePath)
            {
                sb.AppendFormat("\"{0}\" ", CmdKeyPath);
            }
            sb.AppendFormat("/generic:TERMSRV/{0} /user:{1} /pass:{2}",
                            hostPwEntry.IPAddress,
                            hostPwEntry.GetUsername(),
                            hostPwEntry.GetPassword()
                            );
            return(sb.ToString());
        }
コード例 #5
0
        public String Format(IHostPwEntry hostPwEntry)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("\"{0}\"", this.ExecutablePath);

            string ipAddress = null;
            string port      = null;

            if (hostPwEntry.IPAddress.Contains(":"))
            {
                ipAddress = hostPwEntry.IPAddress.Substring(0, hostPwEntry.IPAddress.IndexOf(':'));
                port      = hostPwEntry.IPAddress.Substring(hostPwEntry.IPAddress.IndexOf(':') + 1);
            }
            else
            {
                ipAddress = hostPwEntry.IPAddress;
            }

            PuttyOptions options = null;
            bool         success = PuttyOptions.TryParse(hostPwEntry.AdditionalOptions, out options);

            if (success && options.HasKeyFile())
            {
                sb.AppendFormat(" -i \"{0}\"", options.KeyFilePath);
            }

            if (success && !String.IsNullOrEmpty(options.SessionName))
            {
                ICollection <String> sessionNames = this.PuttySessionFinder.Find(options.SessionName);

                if (sessionNames.Count > 0)
                {
                    sb.AppendFormat(" -load \"{0}\"", new List <String>(sessionNames)[0]);
                }
            }

            if (!success || (success && !options.CommandContainsPort))
            {
                if (port != null)
                {
                    sb.AppendFormat(" -P {0}", port);
                }

                if (port == null && success && options.Port.HasValue)
                {
                    sb.AppendFormat(" -P {0}", options.Port);
                }
            }

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH))
            {
                sb.Append(" -ssh");
            }
            else if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttyTelnet))
            {
                sb.Append(" -telnet");
            }

            sb.AppendFormat(" {0}@{1}", hostPwEntry.GetUsername(), ipAddress);

            // Specifying the password via -pw switch only works with SSH protocol.
            // See: http://the.earth.li/~sgtatham/putty/0.65/htmldoc/Chapter3.html.
            if (this.AppendPassword && hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH))
            {
                // Allow passwords with white-spaces.
                if (!success || (success && !options.CommandContains("-pw ")))
                {
                    var password = hostPwEntry.GetPassword();

                    if (password.Contains(@""""))
                    {
                        sb.AppendFormat(" -pw \"{0}\"", password.Replace(@"""", @"\"""));
                    }
                    else
                    {
                        sb.AppendFormat(" -pw \"{0}\"", password);
                    }
                }
            }

            if (success && options.HasCommand())
            {
                sb.AppendFormat(" {0}", options.Command);
            }

            return(sb.ToString());
        }
コード例 #6
0
        public void ChangePassword(IHostPwEntry hostPwEntry, string newPassword)
        {
            PuttyOptions options = null;
            bool         success = PuttyOptionsParser.TryParse(hostPwEntry.AdditionalOptions, out options);

            var passwordChanger = success && options.Port.HasValue ? this.passwordChangerFactory.Create(options.Port.Value) :
                                  this.passwordChangerFactory.Create();

            passwordChanger.ChangePassword(hostPwEntry.IPAddress, hostPwEntry.GetUsername(), hostPwEntry.GetPassword(), newPassword);
        }
コード例 #7
0
 public void ChangePassword(IHostPwEntry hostPwEntry, string newPassword)
 {
     passwordChanger.ChangePassword(hostPwEntry.IPAddress, hostPwEntry.GetUsername(), hostPwEntry.GetPassword(), newPassword);
     hostPwEntry.UpdatePassword(newPassword);
     hostPwEntry.LastModificationTime = this.clock.Now;
 }