private void buttonBrowse_Click(object sender, EventArgs e) { using (new WaitCursor()) { if (!ValidateRequiredFields(false, true)) { return; } WinInetFTPFileDestination destination = GetDestinationForFields("/"); string path = this.textBoxPath.Text.Trim(); if (!ValidateFTPConnection(destination, false, false)) { return; } string newPath = PublishFolderPicker.BrowseFTPDestination(this.textBoxHostName.Text, destination, path, new ErrorHandler(HandleError), this); if (newPath != null) { this.textBoxPath.Text = newPath; } } }
private bool ValidateFTPConnection(WinInetFTPFileDestination destination, bool verifyMapping, bool permitIgnoringErrors) { if (destination == null) { DisplayMessage.Show(MessageId.ErrorConnecting, FindForm()); return(false); } using (DestinationValidator validator = new DestinationValidator(destination)) { try { validator.Validate(verifyMapping ? textBoxUrlMapping.Text : null); } catch (DestinationValidator.DestinationValidationException ex) { if (ex is DestinationValidator.DestinationLoginFailedException) { DisplayMessage.Show(MessageId.LoginFailed, FindForm(), ApplicationEnvironment.ProductNameQualified); return(false); } else if (ex is DestinationValidator.DestinationServerFailedException) { if (permitIgnoringErrors) { DialogResult result = DisplayMessage.Show(MessageId.ErrorConnectingPromptContinue, FindForm()); if (result == DialogResult.No) { return(false); } else { return(true); } } else { DisplayMessage.Show(MessageId.ErrorConnecting, FindForm()); return(false); } } else if (ex is DestinationValidator.DestinationUrlMappingFailedException) { if (verifyMapping) { DialogResult result = DisplayMessage.Show(MessageId.MappingVerificationFailed, FindForm()); if (result == DialogResult.No) { return(false); } else { return(true); } } else { return(true); } } else { Trace.Fail("Unknown destination validation exception: " + ex.ToString()); } } } return(true); }
private void ConnectForUpload() { if (_fileDestination == null) { try { bool loggedIn = false; FtpCredentials credentials = (FtpCredentials)_credentials[DestinationContext]; string username = credentials != null ? credentials.Username : _settings.Username; string password = credentials != null ? credentials.Password : _settings.Password; while (!loggedIn) { if (password == String.Empty) { CredentialsDomain cd = new CredentialsDomain(Res.Get(StringId.FtpLoginDomain), _settings.FtpServer, null, FtpIconBytes); CredentialsPromptResult result = CredentialsHelper.PromptForCredentials(ref username, ref password, cd); if (result == CredentialsPromptResult.Cancel || result == CredentialsPromptResult.Abort) { throw new OperationCancelledException(); } else { //save the user/pass as appropriate if (result == CredentialsPromptResult.SaveUsername) { _settings.Username = username; _settings.Password = String.Empty; } else if (result == CredentialsPromptResult.SaveUsernameAndPassword) { _settings.Username = username; _settings.Password = password; } } } try { // create and connect to the destination _fileDestination = new WinInetFTPFileDestination( _settings.FtpServer, _settings.PublishPath, username, password); _fileDestination.Connect(); //save the validated credentials so we don't need to prompt again later _credentials[DestinationContext] = new FtpCredentials(DestinationContext, username, password); loggedIn = true; } catch (LoginException) { loggedIn = false; password = String.Empty; _credentials.Remove(DestinationContext); } } // calculate the target path and ensure that it exists _fileDestination.InsureDirectoryExists(PostContext); } catch (Exception ex) { WebPublishMessage message = WebPublishUtils.ExceptionToErrorMessage(ex); throw new BlogClientFileTransferException(Res.Get(StringId.BCEFileTransferConnectingToDestination), message.Title, message.Text); } } }