事先请参阅Wind River Network Stack for VxWorks 6 Programmer's Guide, 6.6的文档!里面的文档说的很详细!

FTP Server

The parameters used to configure the FTP server in Workbench are described in Table 2-9. Authentication callback routine FTPS_AUTH_CALLBACK_HOOK You can use your own routine to authenticate clients. To do this, specify a function pointer for the FTPS_AUTH_CALLBACK_HOOK. The FTP server will call this routine to authenticate clients.

The prototype for this routine is as follows:


int myAuthenticateCallback (Ipftps_session * session, char * password);

It should return 0 (zero) if the password is valid for the session, or 1 (one) if you cannot validate the password. If you do not specify an authentication routine, the server will call its own default authentication callback routine that allows read-only access to the user anonymous with no password.

If you set a function pointer here, you must also set the FTPS_INSTALL_CALLBACK_HOOK to TRUE in order to install this callback hook.


FTPS_INSTALL_CALLBACK_HOOK FALSE

Indicates whether the FTP server uses the authentication callback routine that you specified by the configuration parameter FTPS_AUTH_CALLBACK_HOOK to authenticate clients.

If this is FALSE, the server instead uses its own authentication routine—one that allows the user anonymous with no password.

修改后就是如下面显示:


/*
* FTPS_INSTALL_CALLBACK_HOOK - install ftp server callback routine
* Determine if the user-defined ftp server authentication callback routine
* as specified by the macro FTPS_AUTH_CALLBACK_HOOK should be installed.
* If FALSE, the FTPS_AUTH_CALLBACK_HOOK configuration is not applicable.
*/
#define FTPS_INSTALL_CALLBACK_HOOK   TRUE  //调用自己的回调函数

/*
* FTPS_AUTH_CALLBACK_HOOK - Authentication callback routine.
* User-defined authentication callback routine used by FTP server. If not
* specified, internal authenticaion callback routine will be used. The
* FTPS_INSTALL_CALLBACK_HOOK must also be set to TRUE in order to install
* this callback hook.
*/
#define FTPS_AUTH_CALLBACK_HOOK   myAuthenticateCallback//回调函数

在回调函数里面int myAuthenticateCallback (Ipftps_session * session, char * password)加入自己的判断对password的字符串,对于是否符合的密码!


int myAuthenticateCallback (Ipftps_session * session, char * password)
{
return 0 (zero) if the password is valid//有效地密码!
return 1 (one) if you cannot validate the password//无效!
}

定义宏这样来认证,否则就是If this is FALSE, the server instead uses its own authentication routine—one that allows the user anonymous with no password.

有时自己仔细的看文档就会有帮助!但是VxWorks 6.6的ftp server还是有问题,跟当年的VxWorks 5.5的类似,用图形ftp 客户端的工具登陆的时候还是看不到文件!用DOS的ftp一般可以!风河真是的,这么久了还这样!

另外由于VX6.6 FTP已经默认没有VX5.5的根目录了“/”。需要指定初始化的根目录如tffs0等


#define INCLUDE_IPFTPS
#define FTPS_INITIAL_DIR "/tffs0"

否则无法登陆ftp,响应: 421 Service not available, closing control connection

具体的步骤如下:

在WindRiver\components\ip_net2-6.6\osconfig\vxworks\src\ipnet\下面的ipftps_example.c里面就有


#if FTPS_INSTALL_CALLBACK_HOOK == TRUE
/*
* forward declarations for the user-defined ftp server authentication
* callback hook to satisfy the compiler.
*/
int FTPS_AUTH_CALLBACK_HOOK (Ipftps_session *, char *);
#else
/*
* FTPS_AUTH_CALLBACK_HOOK is applicable only if FTPS_INSTALL_CALLBACK_HOOK
* is set to TRUE. Explicitly re-define to NULL so that we don't get
* compiler errors.
*/
#endif /* FTPS_INSTALL_CALLBACK_HOOK */

修改如下述:


#if FTPS_INSTALL_CALLBACK_HOOK == TRUE
/*
* forward declarations for the user-defined ftp server authentication
* callback hook to satisfy the compiler.
*/
int FTPS_AUTH_CALLBACK_HOOK (Ipftps_session *, char *password);
int myAuthenticateCallback (Ipftps_session * session,char * password)
{
        /*printf("Login attempt with user: %s, pw: %s",session->username, password);*/
       
       if((strcmp(password, "vxworks" ) == 0)&&(strcmp(session->username, "vxworks" ) == 0) )
                {
                        return IPCOM_SUCCESS;
                }
               
                else
                        {
                               
                                return IPCOM_ERR_FAILED;
                        }
       
}
#else
/*
* FTPS_AUTH_CALLBACK_HOOK is applicable only if FTPS_INSTALL_CALLBACK_HOOK
* is set to TRUE. Explicitly re-define to NULL so that we don't get
* compiler errors.
*/
#endif /* FTPS_INSTALL_CALLBACK_HOOK */