コード例 #1
0
        private bool IsValidated()
        {
            if (string.IsNullOrEmpty(txtServer.Text) && string.IsNullOrEmpty(txtLogin.Text) && string.IsNullOrEmpty(txtPassword.Text) && string.IsNullOrEmpty(txtInternalFTPFolder.Text) && string.IsNullOrEmpty(txtExternalWWWFolder.Text))
            {
                this.FTPSettings = null;
                return(true);
            }
            try
            {
                string server = txtServer.Text.Trim();

                if (!server.Contains(@"ftp://"))
                {
                    server = @"ftp://" + server;
                }

                Uri url = new Uri(server);

                string addFolder = txtInternalFTPFolder.Text.Trim();
                if (addFolder != "/")
                {
                    url = new Uri(Path.Combine(url.AbsoluteUri, addFolder.TrimStart('/')));
                }


                NetworkCredential credential;

                if (!url.Scheme.Equals("ftp", StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception("The schema of url must be ftp. ");
                }

                if (url.IsFile)
                {
                    url = new Uri(url, "..");
                }

                if (String.IsNullOrEmpty(txtLogin.Text) ||
                    String.IsNullOrEmpty(txtPassword.Text))
                {
                    throw new Exception("Please type the user name and password!");
                }
                else
                {
                    credential = new NetworkCredential(
                        txtLogin.Text.Trim(),
                        txtPassword.Text);
                }
                this.FTPSettings = new FTPConnection.FTPConnectionSettings(url, credential, txtExternalWWWFolder.Text);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
        }
コード例 #2
0
 internal static void SaveSettings(FTPConnectionSettings settings)
 {
     Properties.Settings.Default.FTP_Server         = settings.Server;
     Properties.Settings.Default.FTP_Login          = settings.Login;
     Properties.Settings.Default.FTP_Password       = settings.Password;
     Properties.Settings.Default.FTP_InternalFolder = settings.InternalFTPFolder;
     Properties.Settings.Default.WWW_ExternalFolder = settings.ExternalWWWFolder;
     Properties.Settings.Default.Save();
 }
コード例 #3
0
 public FTPSettingsDialog(FTPConnectionSettings ftpSettings)
 {
     this.FTPSettings = (FTPConnectionSettings)ftpSettings.Clone();
     InitializeComponent();
     txtServer.Text            = FTPSettings.Server;
     txtLogin.Text             = FTPSettings.Login;
     txtPassword.Text          = FTPSettings.Password;
     txtInternalFTPFolder.Text = FTPSettings.InternalFTPFolder;
     txtExternalWWWFolder.Text = FTPSettings.ExternalWWWFolder;
 }
コード例 #4
0
        internal static FTPConnectionSettings LoadSettings()
        {
            FTPConnectionSettings settings = new FTPConnectionSettings
            {
                Server            = Properties.Settings.Default.FTP_Server,
                Login             = Properties.Settings.Default.FTP_Login,
                Password          = Properties.Settings.Default.FTP_Password,
                InternalFTPFolder = Properties.Settings.Default.FTP_InternalFolder,
                ExternalWWWFolder = Properties.Settings.Default.WWW_ExternalFolder
            };

            return(settings);
        }
コード例 #5
0
 internal static void SaveSettings(FTPConnectionSettings settings)
 {
     if (settings == null)
     {
         Properties.Settings.Default.FTP_Server = Properties.Settings.Default.FTP_Login = Properties.Settings.Default.FTP_Password = Properties.Settings.Default.WWW_ExternalFolder = null;
     }
     else
     {
         Properties.Settings.Default.FTP_Server         = Cryptography.EncryptString(settings.URL.AbsoluteUri);
         Properties.Settings.Default.FTP_Login          = Cryptography.EncryptString(settings.Credential.UserName);
         Properties.Settings.Default.FTP_Password       = Cryptography.EncryptString(settings.Credential.Password);
         Properties.Settings.Default.WWW_ExternalFolder = Cryptography.EncryptString(settings.ExternalWWWFolder);
     }
     Properties.Settings.Default.Save();
     FTPSettingsChanged?.Invoke(settings);
 }
コード例 #6
0
        public FTPSettingsDialog(FTPConnectionSettings ftpSettings)
        {
            InitializeComponent();

            if (ftpSettings != null)
            {
                this.FTPSettings = ftpSettings;
                txtServer.Text   = $"{ftpSettings.URL.Scheme}://{ftpSettings.URL.Host}:{ftpSettings.URL.Port}";
                txtLogin.Text    = ftpSettings.Credential.UserName;
                txtPassword.Text = ftpSettings.Credential.Password;

                txtInternalFTPFolder.Text = ftpSettings.URL.AbsolutePath != "/" ? ftpSettings.URL.AbsolutePath.TrimStart('/') : null;
                txtExternalWWWFolder.Text = FTPSettings.ExternalWWWFolder;
            }
            else
            {
                txtServer.Text = @"ftp://localhost";
            }
        }