最近公司要做一个资料管理模块,因系统是C/S架构,原来小文件都是直接使用7Z压缩后保存到SQL Server数据库
而资料管理模块也就是文件上传,下载加权限管理,考虑文件较多,还可能比较大,所以打算在服务器上直接保存文件。
C/S上传文件到服务器,我知道的有几个实现方法:
1、使用IIS服务,通过B/S方式上传到服务器。这种方式需要服务器上部署IIS,提供WebServers服务,上传文件到指定目录后进行数据库编码保存。
2、使用FTP服务,服务端安装FTP服务器,客户端使用FTP类进行访问,好处是如果以后需要文件管理,可以直接使用现有的客户端进行管理。
3、使用TCP通讯方式上传下载。这种方式还需要处理很多问题。
经过几番查找,对比,决定使用第二种方式,使用开源的FileZilla 进行管理
使用FTP方式,就必须能实现服务端能在程序中控制,比如,在系统中添加用户,则服务器也同时能对FTP服务端添加用户操作,及权限分配。
经研究FileZilla Server使用XML配置文件管理,其分支结构非常清晰。
如图:


这是V9.46版本的配置文件,最新版本V9.60已修改了加密方式,添加了SHA512加密,方法还是一样,也可以直接使用C#生成。
 static string md5(string a)
        {
            string pwd = "";
            MD5 md5 = MD5.Create();
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(a));
            for (int i = 0; i < s.Length; i++)
            {
                pwd = pwd + s[i].ToString("x2"); 
            }           
            return pwd;       
        }
此方法来源:http://blog.sina.com.cn/s/blog_589b38e70100rtse.html
修改配置文件后需要重新加载,使配置文件生效:
官方手册使用命令行方式 /reload-config 命令就可以重新加载数据了
-------------- "FileZilla Server.exe" Command-line arguments ------------------Starting and stopping the service:
/start
/stop
Installing the service for manual startup:
/install
Installing the service for start at boot:
/install auto
Uninstalling service:
/uninstall
Reloading configuration at runtime:
/reload-config
重新加载参考:http://www.tuicool.com/articles/AzQBfmU
最新版本V6.0以后 密码生成:

代码:
string txt=@"<Root><salt><RhUrxf^l,VZ&7I/rbT+V9ZIr@v\p'^cEmPEWyYMjS8^&HY1Z|J.2#u2Z}]HF0i9</salt></Root>";
XmlDocument xmldoc=new XmlDocument();
xmldoc.LoadXml(txt);
 
 string oldPass="05087D2082B206535713C1D5BDCA35509BE70B8C4F513F7E5F9799187DCB7F366011DB51AFACC67D1035A8EE7C04C6C12E92A4330808DDA4FF9F9946A09076FA";
 string pass="123";
 string salt=xmldoc.ChildNodes[0].InnerText;
salt.Dump();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass+salt);  
               
                SHA512 sha512 = new SHA512CryptoServiceProvider();  
                byte[] retVal = sha512.ComputeHash(bytValue);  
                StringBuilder sb = new StringBuilder();  
                for (int i = 0; i < retVal.Length; i++)  
                {  
                    sb.Append(retVal[i].ToString("X2"));  
                }  
             
		 
   bool isComp=      (   oldPass==sb.ToString());
   isComp.Dump();
FTP FileZilla Server 本地加密C# 实现
原文:http://www.cnblogs.com/hdl217/p/6537533.html