Beispiel #1
0
        public SFTPManager(String _hostname, String _username, String _password, String _privatekey, String _pk_pwd)
        {
            InitializeComponent();

            if (DPIAwareScaling.UsingWindows7ClassicTheme())
            {
                progressBar1.BackColor = SystemColors.Control;
                progressBar1.ForeColor = Color.Green;

                progressBar2.BackColor = SystemColors.Control;
                progressBar2.ForeColor = Color.Green;
            }

            this.hostname      = _hostname;
            this.username      = _username;
            this.password      = _password;
            this.PrivateKey    = _privatekey;
            this.KeyPassphrase = _pk_pwd;

            // Use KeyboardInteractiveAuthentication or PasswordAuthenticationMethod
            if (this.password != null && this.password != "" && !Regex.IsMatch(this.password, @"\s+") && this.PrivateKey == null)
            {
                Console.WriteLine("## SFTP Manager using password for login");

                KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(this.username);
                keybAuth.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent);

                con = new ConnectionInfo(this.hostname, 22, this.username, new AuthenticationMethod[]
                {
                    new PasswordAuthenticationMethod(this.username, this.password),
                    keybAuth
                });
            }
            // Otherwise we have setup PrivateKeyAuthenticationMethod
            else if (this.password == null && this.PrivateKey != null)
            {
                Console.WriteLine("## SFTP Manager using OpenSSH private key for login");

                PrivateKeyFile keyFile;
                if (this.KeyPassphrase == null)
                {
                    Console.WriteLine("## OpenSSH private key is not encrypted");
                    keyFile = new PrivateKeyFile(this.PrivateKey);
                }
                else
                {
                    Console.WriteLine("## OpenSSH private key IS encrypted!");
                    keyFile = new PrivateKeyFile(this.PrivateKey, this.KeyPassphrase);
                }

                var keyFiles = new[] { keyFile };
                con = new ConnectionInfo(this.hostname, 22, this.username, new PrivateKeyAuthenticationMethod(this.username, keyFiles));
            }
        }
Beispiel #2
0
        /// <summary>
        /// This is evil but we need it to prevent Windows DPI scaling issues :(
        /// </summary>
        public static void SetControlsExtendedDPISettings()
        {
            Console.WriteLine("## Display's DPI:");
            Console.WriteLine("# X: " + graphics.DpiX);
            Console.WriteLine("# Y: " + graphics.DpiY);
            Console.WriteLine("# Windows version: " + Environment.OSVersion.Version);

            if (DPIAwareScaling.graphics.DpiX == 96 && DPIAwareScaling.graphics.DpiY == 96)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -25;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 10;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 10;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 10;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 10;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 10;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 10;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -8;
                    DPIAwareScaling.MoveWindowY       = -31;
                    DPIAwareScaling.MoveWindowNWidth  = 5;
                    DPIAwareScaling.MoveWindowNHeight = 6;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 10;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 10;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 10;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 10;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 10;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 10;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 120 && DPIAwareScaling.graphics.DpiY == 120)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -28;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 11;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 11;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 11;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 11;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 11;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 11;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1050);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -9;
                    DPIAwareScaling.MoveWindowY       = -38;
                    DPIAwareScaling.MoveWindowNWidth  = 6;
                    DPIAwareScaling.MoveWindowNHeight = 6;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 11;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 11;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 11;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 11;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 11;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 11;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1050);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 144 && DPIAwareScaling.graphics.DpiY == 144)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -33;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -12;
                    DPIAwareScaling.MoveWindowY       = -50;
                    DPIAwareScaling.MoveWindowNWidth  = 15;
                    DPIAwareScaling.MoveWindowNHeight = 12;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 168 && DPIAwareScaling.graphics.DpiY == 168)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -39;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1020);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -12;
                    DPIAwareScaling.MoveWindowY       = -52;
                    DPIAwareScaling.MoveWindowNWidth  = 15;
                    DPIAwareScaling.MoveWindowNHeight = 12;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1020);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 192 && DPIAwareScaling.graphics.DpiY == 192)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -42;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -13;
                    DPIAwareScaling.MoveWindowY       = -58;
                    DPIAwareScaling.MoveWindowNWidth  = 15;
                    DPIAwareScaling.MoveWindowNHeight = 13;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 12;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 12;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 12;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 12;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 12;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(980);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 216 && DPIAwareScaling.graphics.DpiY == 216)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -45;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1025);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -14;
                    DPIAwareScaling.MoveWindowY       = -65;
                    DPIAwareScaling.MoveWindowNWidth  = 23;
                    DPIAwareScaling.MoveWindowNHeight = 13;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 11;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1025);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 240 && DPIAwareScaling.graphics.DpiY == 240)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -48;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1050);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -16;
                    DPIAwareScaling.MoveWindowY       = -72;
                    DPIAwareScaling.MoveWindowNWidth  = 23;
                    DPIAwareScaling.MoveWindowNHeight = 14;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1050);
                }
            }
            else if (DPIAwareScaling.graphics.DpiX == 288 && DPIAwareScaling.graphics.DpiY == 288)
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -51;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1070);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -18;
                    DPIAwareScaling.MoveWindowY       = -85;
                    DPIAwareScaling.MoveWindowNWidth  = 24;
                    DPIAwareScaling.MoveWindowNHeight = 16;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1070);
                }
            }
            else
            {
                if (DPIAwareScaling.UsingWindows7ClassicTheme())
                {
                    DPIAwareScaling.MoveWindowX       = -5;
                    DPIAwareScaling.MoveWindowY       = -54;
                    DPIAwareScaling.MoveWindowNWidth  = -1;
                    DPIAwareScaling.MoveWindowNHeight = -5;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1070);
                }
                else
                {
                    DPIAwareScaling.MoveWindowX       = -18;
                    DPIAwareScaling.MoveWindowY       = -85;
                    DPIAwareScaling.MoveWindowNWidth  = 24;
                    DPIAwareScaling.MoveWindowNHeight = 16;

                    DPIAwareScaling.NewConnectHostTextboxFont      = 13;
                    DPIAwareScaling.NewConnectUsernameTextboxFont  = 13;
                    DPIAwareScaling.NewConnectPasswordTextboxFont  = 13;
                    DPIAwareScaling.NewConnectSearchTextboxFont    = 13;
                    DPIAwareScaling.NewConnectNumericUpDownFont    = 13;
                    DPIAwareScaling.SearchSessionConfigTextBoxFont = 12;
                    DPIAwareScaling.TabcontrolFont             = 10;
                    DPIAwareScaling.TabControlSplitterDistance = 75;
                    DPIAwareScaling.KotarakSplitterDistance    = DPIAwareScaling._ScaleX(1070);
                }
            }
        }