FTP 7.5 自定义扩展功能
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
参考: http://gzzhang.blog.51cto.com/5312382/1125092
随着IIS7的发布,IIS自带的FTP终于能自定义验证了.
目前知道的自定义接口共三个 自定义校验, 自定义主目录,自定义日志
分别是 Microsoft.Web.FtpServer的
步骤:
1. 首先创建 C#类库 (要选择 2.0 / 3.5 框架) ,有说 .NET 4.0不支持 ,但是这个没做验证,需要后期继续测试
2. 然后增加生成事件 后期处理 VS2012版本:
3. 添加签名(无密码)
4. 代码
namespace FtpHomeDirectory
{
public class FtpHomeDirDemo : BaseProvider,
IFtpHomeDirectoryProvider
{
string IFtpHomeDirectoryProvider.GetUserHomeDirectoryData(
string sessionId,
string siteName,
string userName)
{
// Note: You would add your own custom logic here.
// Return the user's home directory based on their user name.
string homedir = @"D:\Ftptest\" + userName;
VASLog.WriteLog_day(@"d:\Ftptest", "ftplog", "siteName: " + siteName + " 用户想要得到的目录是:"+homedir+" ;");
return homedir;
}
}
}
密码验证
namespace FtpAuthenticationDemo
{
public class FtpAuthDemo : BaseProvider,
IFtpAuthenticationProvider,
IFtpRoleProvider
{
//void IFtpLogProvider.Log(FtpLogEntry loggingParameters)
//{
// // Note: You would add your own custom logic here.
// // Open the log file for output.
// using (StreamWriter sw =
// new StreamWriter(@"C:\inetpub\logs\LogFiles\FTPSVC8\myftplog.log", true))
// {
// // Retrieve the current date and time for the log entry.
// DateTime dt = DateTime.Now;
// // Retrieve the user name.
// string un = loggingParameters.UserName;
// // Write the log entry to the log file.
// sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
// dt.ToShortDateString(),
// dt.ToLongTimeString(),
// loggingParameters.RemoteIPAddress,
// (un.Length == 0) ? "-" : un,
// loggingParameters.Command,
// loggingParameters.SessionId);
// }
//}
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 = "test";
//string strPassword = "123";
VASLog.WriteLog_day(@"d:\Ftptest", "ftplog", canonicalUserName + " siteName: " +siteName +" 校验总是可以成功的;");
return true;
// 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 true;
//}
}
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";
//VASLog.WriteLog_day(@"d:\Ftptest", "ftplog", "IsUserInRole");
return true;
// 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;
}
}
//string IFtpHomeDirectoryProvider.GetUserHomeDirectoryData(
// string sessionId,
// string siteName,
// string userName)
//{
// VASLog.WriteLog_day(@"d:\Ftptest", "ftplog", "GetUserHomeDirectoryData");
// // Note: You would add your own custom logic here.
// // Return the user's home directory based on their user name.
// return @"d:\FtpTest\" + userName;
//}
}
}
尽量两个分开吧
生成后,在输出里可以看到
然后要做的,就是配置IIS了
1. 在IIS的根基目录中,配置 FTP身份验证,禁用其他选项,在右侧自定义提供程序中,注册刚才的DLL,
2. FTP规则里,允许所有账户
3. 同样的注册主目录DLL
4. 跟密码验证不同,主目录的DLL,还需要设置两个地方
cd %systemroot%/system32/Inetsrv/
AppCmd set site "YourFTP" /+ftpServer.customFeatures.providers.[name='FtpHomeDirectoryDemo',enabled='true']
AppCmd set site "YourFTP" /ftpServer.userIsolation.mode:Custom
注意: 第一个appcmd 里面的 name = ftphomedirectorydemo 这个name,是在上面注册在IIS里的名称,跟DLL的空间类名没关系,一定要注意
这个一定要执行,不然,修改了数据库的密码之后,依然旧密码要保留一点时间,但是原因是什么,不理解.
现象,好像是登录时,直接就过了验证,进入到了目录获取的地方去了.
这样设置之后,才能启用主目录的设置
5. 在FTP用户隔离里,选择 下面的 用户名目录(禁用全局虚拟目录) ,这个用不用,还不知道,有待测试! 原理上考虑,这个其实没作用了,毕竟主目录在DLL里,已经可以定义了
这里应该在FTP用户隔离 属性设置中,改成自定义(简单测试了下,好像是这样)
这里有个好玩的,如果继续设置LocalUser虚拟目录(物理目录也可以的),指向了同名FTP用户名的文件夹下面,
这时候设置IP限制之类的,也是生效的,这样子,可以针对单独的FTP做限制了。
FTP 7.5 自定义扩展功能的更多相关文章
- Java 自定义FTP连接池
转自:https://blog.csdn.net/eakom/article/details/79038590 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...
- 虚拟机中使用centos7搭建ftp服务器
应用场景 本地windows作为客户端,虚拟机CentOS7作为服务器端,搭建FTP服务器,本地访问虚拟机实现文件的上传下载.如何在虚拟机安装centos7就不在赘述. 1.在centos7上安装vs ...
- FTP和TCP的文件传输效率对比测试分析
前言 最近因项目需要,需要把一定数量的中等文件从开发板上传到电脑上,分别选择了FTP和TCP自定义协议两种方式进行传输,进行了简单的对比测试,故做如下记录. 测试环境 开发板:Linux,ARMv7 ...
- 一文看懂web服务器、应用服务器、web容器、反向代理服务器区别与联系
我们知道,不同肤色的人外貌差别很大,而双胞胎的辨识很难.有意思的是Web服务器/Web容器/Web应用程序服务器/反向代理有点像四胞胎,在网络上经常一起出现.本文将带读者对这四个相似概念如何区分. 1 ...
- Web服务器、应用服务器、Web容器、反向代理服务器区别与联系
作者: 帅虫哥 出处:www.cnblogs.com/vipyoumay/p/7455431.html(点击尾部阅读原文前往) 我们知道,不同肤色的人外貌差别很大,而双胞胎的辨识很难.有意思的是Web ...
- [转帖]一文看懂web服务器、应用服务器、web容器、反向代理服务器区别与联系
一文看懂web服务器.应用服务器.web容器.反向代理服务器区别与联系 https://www.cnblogs.com/vipyoumay/p/7455431.html 我们知道,不同肤色的人外貌差别 ...
- Membership三步曲之入门篇 - Membership基础示例
Membership 三步曲之入门篇 - Membership基础示例 Membership三步曲之入门篇 - Membership基础示例 Membership三步曲之进阶篇 - 深入剖析Pro ...
- Android Weekly Notes Issue #232
Android Weekly Issue #232 November 20th, 2016 Android Weekly Issue #232 本期内容包括: Kotlin的优势讨论; MVVM模式结 ...
- 开源免费的HTML5游戏引擎
青瓷引擎的成长 青瓷引擎自2015年4月项目启动开始,7月首次亮相2015年ChinaJoy,便得到业界的极大关注,随后开启限量测试,收到数百个开发者团队的试用申请及反馈,期间经历了18个内测版本,完 ...
随机推荐
- a标签中使用img后的高度多了几个像素
a元素下有一个匿名文本,这个文本外有一个匿名行级盒子,它有的默认vertical-align是baseline的,而且往往因为上文line-height的影响,使它有个line-height,从而使其 ...
- 网页 HTML表单
今天,我首先先学习了图片热点和在原来页面嵌入其他页面. 图片热点:<img src="" usemap="#ditu"/> <map name ...
- Set下面HashSet,TreeSet和LinkedHashSet的区别
Set接口Set不允许包含相同的元素,如果试图把两个相同元素加入同一个集合中,add方法返回false.Set判断两个对象相同不是使用==运算符,而是根据equals方法.也就是说,只要两个对象用eq ...
- jquery ui sortable 实现table,row的拖动。(Make Table Rows Sortable Using jQuery UI Sortable)
// Return a helper with preserved width of cells var fixHelper = function(e, ui) { //console.log(ui) ...
- stm32按键识别
刚写了一个关于stm32单片机的按键识别的程序.目的,同时识别多个按键,并且不浪费cpu的时间. 关于去抖动,以前以为是在按键的时候,手会抖动.通过程序验证,这个确实是误解.这个应该是防止意外干扰.以 ...
- (1)Two Sum--求数组中相加为指定值的两个数
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- xxx app 项目问题解决一览
前话:作为人生旅途中的小记录 不同账号玩法限制 解决 <vn_rule>x</vn_rule> 6.调整下注筹码 **** 解决 不同账号的玩法限制 **** ...
- C# 获取字符的Unicode编码
using UnityEngine;using System.Collections;using System.Collections.Generic; List<); string chars ...
- VirtualBox中安装CentOS(新手教程)
1.VirtualBox下载 官网:http://www.virtualbox.org/wiki/Downloads 下载好之后,一路下一步安装即可 2.CentOS下载 官网:https://www ...
- SCANF SCANF_S
今天在看C的教程的时候,用VS2013写了一小段代码 scanf("%f",&w); 提示需要在预编译器里添加 _CRT_SECURE_NO_WARNINGS, 百度了下 ...