public static string BrowseFTPDestination(string name, WinInetFTPFileDestination destination, string currentPath, ErrorHandler errorHandler, IWin32Window owner)
        {
            PublishFolderPicker folderPicker = new PublishFolderPicker(name, errorHandler);

            using (folderPicker)
            {
                try
                {
                    using (new WaitCursor())
                        destination.Connect();

                    folderPicker.Destination = destination;

                    //default the selected path to what's in the textField (if it exists!)
                    if (!currentPath.Equals(""))
                    {
                        if (!currentPath.StartsWith("/", StringComparison.OrdinalIgnoreCase))
                        {
                            currentPath = destination.HomeDir + "/" + currentPath;
                        }
                        folderPicker.SelectedPath = currentPath;
                    }
                    else
                    {
                        string currDirectory = destination.HomeDir;
                        if (!currDirectory.StartsWith("/", StringComparison.OrdinalIgnoreCase))
                        {
                            currDirectory = "/" + currDirectory;
                        }
                        folderPicker.SelectedPath = currDirectory;
                    }

                    if (folderPicker.ShowDialog(owner) == DialogResult.OK)
                    {
                        return(folderPicker.SelectedPath);
                    }
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
                finally
                {
                    try
                    {
                        destination.Disconnect();
                    }
                    catch (Exception)
                    {
                        //eat it since we've already reported the error and this error
                        //is probably because no valid connection was ever established
                    }
                }
                return(null);
            }
        }
        public static string BrowseFTPDestination(string name, WinInetFTPFileDestination destination, string currentPath, ErrorHandler errorHandler, IWin32Window owner)
        {
            PublishFolderPicker folderPicker = new PublishFolderPicker(name, errorHandler);
            using (folderPicker)
            {
                try
                {
                    using (new WaitCursor())
                        destination.Connect();

                    folderPicker.Destination = destination;

                    //default the selected path to what's in the textField (if it exists!)
                    if (!currentPath.Equals(""))
                    {
                        if (!currentPath.StartsWith("/", StringComparison.OrdinalIgnoreCase))
                        {
                            currentPath = destination.HomeDir + "/" + currentPath;
                        }
                        folderPicker.SelectedPath = currentPath;
                    }
                    else
                    {
                        string currDirectory = destination.HomeDir;
                        if (!currDirectory.StartsWith("/", StringComparison.OrdinalIgnoreCase))
                            currDirectory = "/" + currDirectory;
                        folderPicker.SelectedPath = currDirectory;
                    }

                    if (folderPicker.ShowDialog(owner) == DialogResult.OK)
                    {
                        return folderPicker.SelectedPath;
                    }
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                        errorHandler(ex);
                }
                finally
                {
                    try
                    {
                        destination.Disconnect();
                    }
                    catch (Exception)
                    {
                        //eat it since we've already reported the error and this error
                        //is probably because no valid connection was ever established
                    }
                }
                return null;
            }
        }
        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);
                }
            }
        }
        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;
        }