FTP服务器源码Word文档格式.docx

上传人:b****7 文档编号:22574671 上传时间:2023-02-04 格式:DOCX 页数:15 大小:16.84KB
下载 相关 举报
FTP服务器源码Word文档格式.docx_第1页
第1页 / 共15页
FTP服务器源码Word文档格式.docx_第2页
第2页 / 共15页
FTP服务器源码Word文档格式.docx_第3页
第3页 / 共15页
FTP服务器源码Word文档格式.docx_第4页
第4页 / 共15页
FTP服务器源码Word文档格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

FTP服务器源码Word文档格式.docx

《FTP服务器源码Word文档格式.docx》由会员分享,可在线阅读,更多相关《FTP服务器源码Word文档格式.docx(15页珍藏版)》请在冰豆网上搜索。

FTP服务器源码Word文档格式.docx

port"

Portonwhichtolisten.<

publicls_FTP_Server(stringftpRootDir,stringip,intport)

{

m_FtpRoot=ftpRootDir;

m_pServer=newLumiSoft.Net.FTP.Server.FTP_Server();

this.m_pServer.CommandIdleTimeOut=60000;

this.m_pServer.LogCommands=false;

this.m_pServer.MaxBadCommands=30;

this.m_pServer.SessionIdleTimeOut=800000;

this.m_pServer.Port=port;

this.m_pServer.IpAddress=ip;

this.m_pServer.CreateDir+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnCreateDir);

this.m_pServer.StoreFile+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnStoreFile);

this.m_pServer.DeleteDir+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnDeleteDir);

this.m_pServer.SysError+=newLumiSoft.Net.ErrorEventHandler(this.OnSysError);

this.m_pServer.DirExists+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnDirExists);

this.m_pServer.FileExists+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnFileExists);

this.m_pServer.RenameDirFile+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnRenameDirFile);

this.m_pServer.DeleteFile+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnDeleteFile);

this.m_pServer.ValidateIPAddress+=newLumiSoft.Net.ValidateIPHandler(this.OnValidateIP);

this.m_pServer.GetFile+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnGetFile);

this.m_pServer.GetDirInfo+=newLumiSoft.Net.FTP.Server.FileSysEntryEventHandler(this.OnGetDirInfo);

this.m_pServer.AuthUser+=newLumiSoft.Net.FTP.Server.AuthUserEventHandler(this.OnAuthUser);

m_pServer.Enabled=true;

}

 

#regionEventshandling

#regionFTPserverevents

#regionmethodOnAuthUser

publicvoidOnValidateIP(objectsender,ValidateIP_EventArgse)

{

e.Validated=true;

#endregion

publicvoidOnAuthUser(objectsender,AuthUser_EventArgse)

if(Impersonate.LogonAndImpersonateUser(e.UserName,e.PasswData)){

e.Validated=true;

}

else{

e.Validated=false;

#regionmethodOnGetDirInfo

publicvoidOnGetDirInfo(objectsender,FileSysEntry_EventArgse)

try{

DataTabledt=e.DirInfo.Tables["

DirInfo"

];

stringphysicalPath=GetPhysicalPath(e.Name);

//Adddirectories

if(Directory.Exists(physicalPath)){

string[]dirs=Directory.GetDirectories(physicalPath);

foreach(stringdindirs){

DataRowdr=dt.NewRow();

dr["

Name"

]=newDirectoryInfo(d).Name;

Date"

]=Directory.GetCreationTime(d);

//dr["

Size"

]="

IsDirectory"

]=true;

dt.Rows.Add(dr);

}

//Addvirtualfolders

if(File.Exists(physicalPath+"

__Config_ftp.xml"

)){

try{

DataSetds=newDataSet();

ds.ReadXml(physicalPath+"

);

foreach(DataRowdrinds.Tables["

virtualFolder"

].Rows){

//ToDo:

ifvirtualfolderissamenameasphysicalfolder

//Addvitualfoldertolistonlyifitexists

stringvDirPhysicalPath=dr["

path"

].ToString();

if(Directory.Exists(vDirPhysicalPath)){

DataRowdrX=dt.NewRow();

drX["

]=dr["

name"

]=Directory.GetCreationTime(vDirPhysicalPath);

//drX["

dt.Rows.Add(drX);

}

}

}

catch{

//Addfiles

string[]files=Directory.GetFiles(physicalPath);

foreach(stringfinfiles){

//Hideconfigfile

if(Path.GetFileName(f).ToLower()!

="

__config_ftp.xml"

){

DataRowdr=dt.NewRow();

dr["

]=Path.GetFileName(f);

]=File.GetCreationTime(f);

]=newFileInfo(f).Length;

]=false;

dt.Rows.Add(dr);

}

catch{

#regionmethodOnDirExists

publicvoidOnDirExists(objectsender,FileSysEntry_EventArgse)

if(!

Directory.Exists(GetPhysicalPath(e.Name))){

#regionmethodOnCreateDir

publicvoidOnCreateDir(objectsender,FileSysEntry_EventArgse)

{

if(Directory.Exists(GetPhysicalPath(e.Name))){

Directory.CreateDirectory(GetPhysicalPath(e.Name));

#regionmethodOnDeleteDir

publicvoidOnDeleteDir(objectsender,FileSysEntry_EventArgse)

{

IsVirtualDir(e.Name)&

&

Directory.Exists(GetPhysicalPath(e.Name))){

Directory.Delete(GetPhysicalPath(e.Name));

else{

#regionmethodOnRenameDirFile

publicvoidOnRenameDirFile(objectsender,FileSysEntry_EventArgse)

//Removelast/

stringto=e.NewName.Substring(0,e.NewName.Length-1);

stringfrom=e.Name.Substring(0,e.Name.Length-1);

if(IsVirtualDir(to)||IsVirtualDir(from)||Directory.Exists(GetPhysicalPath(to))||File.Exists(GetPhysicalPath(to))){

if(Directory.Exists(GetPhysicalPath(from))){

Directory.Move(GetPhysicalPath(from),GetPhysicalPath(to));

}

elseif(File.Exists(GetPhysicalPath(from))){

File.Move(GetPhysicalPath(from),GetPhysicalPath(to));

}

#regionmethodOnFileExists

publicvoidOnFileExists(objectsender,FileSysEntry_EventArgse)

try{

if(File.Exists(GetPhysicalPath(e.Name))){

e.Validated=true;

#regionmethodOnGetFile

publicvoidOnGetFile(objectsender,FileSysEntry_EventArgse)

e.FileStream=File.OpenRead(GetPhysicalPath(e.Name));

#regionmethodOnStoreFile

publicvoidOnStoreFile(objectsender,FileSysEntry_EventArgse)

if(!

File.Exists(GetPhysicalPath(e.Name))){

e.FileStream=File.Create(GetPhysicalPath(e.Name));

#regionmethodOnDeleteFile

publicvoidOnDeleteFile(objectsender,FileSysEntry_EventArgse)

if(File.Exists(GetPhysicalPath(e.Name))){

File.Delete(GetPhysicalPath(e.Name));

#regionmethodOnSysError

publicvoidOnSysError(objectsender,Error_EventArgse)

Error.DumpError(e.Exception,e.StackTrace);

#regionmethodGetPhysicalPath

///Getsphysicalpathfromabsolutepath(replacesvirtualfolderswithrealpath).

<

returns>

/returns>

privatestringGetPhysicalPath(stringpath)

stringpPath=m_FtpRoot+"

\\"

boolendsWithSep=false;

if(path.StartsWith("

/"

path=path.Substring(1,path.Length-1);

if(path.EndsWith("

path=path.Substring(0,path.Length-1);

endsWithSep=true;

string[]pathParts=path.Split('

/'

'

\\'

foreach(stringpartinpathParts){

if(part.Length>

0){

//Thisisphysicaldirectory

if(Directory.Exists(pPath+part)){

pPath+=part+"

else{

//Seeifvirtualfolder

if(File.Exists(pPath+"

)){

try{

DataSetds=newDataSet();

ds.ReadXml(pPath+"

ds.Tables["

].DefaultView.RowFilter="

name='

+part+"

'

if(ds.Tables["

].DefaultView.Count>

0){

pPath=ds.Tables["

].DefaultView[0]["

if(!

pPath.EndsWith("

pPath+="

}

else{

pPath+=part+"

catch{

else{

pPath+=part+"

endsWithSep&

pPath.EndsWith("

pPath=pPath.Substring(0,pPath.Length-1);

returnpPath;

#regionmethodIsVirtualDir

///Getsifspecifieddirisvirtualdirectory.

dir"

privateboolIsVirtualDir(stringdir)

if(dir.StartsWith("

dir=dir.Substring(1,dir.Length-1);

if(dir.EndsWith("

dir=dir.Substring(0,dir.Length-1);

stringpPath="

//---Movedirupandgetphysicalpath

string[]pathParts=dir.Split('

if(pathParts.Length>

1){

//pPath="

for(inti=0;

i<

(pathParts.Length-1);

i++){

pPath+=pathParts[i]+"

if(pPath.Length==0){

pPath="

//else{

//}

pPath=GetPhysicalPath(pPath);

//---------------------------------------------

Directory.Exists(pPath+pathParts[pathParts.Length-1])){

//Seeifvirtualfolder

if(File.Exists(pPath+"

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学反思汇报

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1