WinCE5.0下设置FTP(一)

来源:互联网 发布:阿里云人才市场 编辑:程序博客网 时间:2024/05/23 11:54

沈阳的客户要求我们提供的系统具有FTP功能,并可设置用户和密码,下面粗略的写一下设置过程:

首先要将FTP组件加到系统中来,这是开展下一步工作的基础,接下来修改platform.reg文件,添加如下信息:
[HKEY_LOCAL_MACHINE/COMM/FTPD]
    "AllowAnonymous"=dword:0                        ;Determines whether the server will allow anonymous access.
    "AllowAnonymousUpload"=dword:1           ;Determines whether authorization is required to upload files to the server, delete files from the server, and rename files.
    "AllowAnonymousVroots"=dword:1             ;Specifies whether access to virtual roots is granted or denied to anonymous users.
    "DefaultDir"="//Hard Disk//FtpRoot"             ;Default root directory. Directory and subdirectories of this key are accessible remotely. If this value is not set in the registry, the default is /Temp.
    "IsEnabled"=dword:1                                      ;Determines whether or not the server will accept incoming connections. This value is typically used to keep the server disabled at boot time.
    "UseAuthentication"=dword:1                       ;Determines whether authorization is required to connect to the server. Determines whether the client needs to send a USER and PASS pair before being allowed to issue other commands.
    "UserList"=""

上面的各项注释写得很清楚,关于此处的设置,MSDN地址为:http://msdn2.microsoft.com/en-us/library/ms901310.aspx

编译好的NK运行后还不能通过FTP进行访问,因为我们还没有给FTP Server添加用户,添加用户有点麻烦,要自己写些代码,部分代码如下:

typedef BOOL ( *PFnSetUser )(IN LPCTSTR pszUser, IN LPCTSTR pszPassword);

hDllModule = LoadLibrary( _T("ntlmssp.dll") );

if (NULL == hDllModule)
 {
  return FALSE;
 }

PFnSetUser pFnSetUser = (PFnSetUser)GetProcAddress(hDllModule, _T("NTLMSetUserInfo"));

if(!pFnSetUser)
 {
  return FALSE;    
 }

return pFnSetUser( szName, szPwd );  

通过上面的代码,我们就可以为系统添加用户,通过远程工具,我们可以在系统注册表中看到已经加载的用户. 具体位置:HKEY_LOCAL_MACHINE/Comm/Security/UserAccounts.

不过只加了系统用户还不行,因为还没有给这个用户访问FTP的权限,我们前 面在platform.reg中设置FTP参数时最后有一项是UserList, 对了,这里就是添加FTP用户的地方,可以参考前面给出的MSDN地址中关于此处的设置,多个用户之前要用分号(;)隔开, 如:

"UserList"="User1;User2"

至此你会发现我们终于可以用添加的用户名登陆FTP服务器了.通过以上操作,FTP Server的基本功能就设置完了.