locked
Custom FTP authentication provider RRS feed

  • Question

  • User1830143703 posted

    Hi.

    I'm trying to develop a custom authentication provider but even the simple example from Microsoft page isn't working... what am I doing wrong?

    Example below.

    In my IIS configuration I've added a custom authentication provider and basic authentication. My custom authentication provider link:

    FtpTest.FtpAuthDemo, FtpTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f2c1943dc593cb2b, processorArchitecture=MSIL

    When I'm trying to connect co FTP by CMD (using user from example) I get:

    530-User cannot log in.

    Win32 error:

    Error details: An error occurred during authentication process.

    And no more info, no log etc. Please help. Thanks

    using System;
    using Microsoft.Web.FtpServer;
    
    namespace FtpAuthentication
    {
        public class FtpAuthDemo : BaseProvider,
            IFtpAuthenticationProvider,
            IFtpRoleProvider
        {
            bool IFtpAuthenticationProvider.AuthenticateUser(
                string sessionId,
                string siteName,
                string userName,
                string userPassword,
                out string canonicalUserName)
            {
                // Note: You would add your own custom logic here.
                canonicalUserName = userName;
                string strUserName = "MyUser";
                string strPassword = "MyPassword";
    
                // Verify that the user name and password are valid.
                // Note: In this example, the user name is case-insensitive
                // and the password is case-sensitive.
                if (((userName.Equals(strUserName,
                    StringComparison.OrdinalIgnoreCase)) == true) &&
                    userPassword == strPassword)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            bool IFtpRoleProvider.IsUserInRole(
                string sessionId,
                string siteName,
                string userName,
                string userRole)
            {
                // Note: You would add your own custom logic here.
                string strUserName = "MyUser";
                string strRoleName = "MyRole";
    
                // Verify that the user name and role name are valid.
                // Note: In this example, both the user name and
                // the role name are case-insensitive.
                if (((userName.Equals(strUserName,
                    StringComparison.OrdinalIgnoreCase)) == true) &&
                    ((userRole.Equals(strRoleName,
                    StringComparison.OrdinalIgnoreCase)) == true))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }


     

    Sunday, October 9, 2016 3:59 PM

Answers

  • User-2057865890 posted

    Hi Lacrim,

    Lacrim

    When I'm trying to connect co FTP by CMD (using user from example) I get:

    530-User cannot log in.

    Win32 error:

    Error details: An error occurred during authentication process.

    Have you tried the following steps?

    Add the custom authentication provider for an FTP site:

    • Open an FTP site in the Internet Information Services (IIS) Manager.
    • Double-click FTP Authentication in the main window.
    • Click Custom Providers... in the Actions pane.
    • Check "custom provider name" in the providers list.
    • Click OK.

    Add an authorization rule for the authentication provider:

    • Double-click FTP Authorization Rules in the main window.
    • Click Add Allow Rule... in the Actions pane.
    • You can add either of the following authorization rules:
    • For a specific user:
    • Select Specified users for the access option. Enter the user name.
    • For a role or group: Select Specified roles or user groups for the access option.
    • Enter the role or group name. For example, using the XML sample in this walkthrough you could enter "Members" or "Administrators".
    • Select Read and/or Write for the Permissions option.
    • Click OK.

    reference: https://www.iis.net/learn/develop/developing-for-ftp/how-to-use-managed-code-c-to-create-an-ftp-authentication-provider-using-an-xml-database 

    Follow below mentioned steps to restart Microsoft FTP Services:

    Open Services [Start → Run → type service.msc and Hit Enter].

    Select the service named Microsoft FTP Service.

    Click on Restart link from the left pane option.

    Besides, please consider posting IIS related questions to http://forums.iis.net/. You may get quicker and better responses there.

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 12:10 PM