RemoteExplorer.asp

A directory Viewer with the option of downloading the file and reading text
Directory Viewer with Download


Public

Tested

My Own Work
<--- Remoteexplorer.asp --->
<%@ Language=VBScript %>
<%
Option Explicit
Dim giCount
Dim gvAttributes
Dim Ext
Dim ScriptFolder
Dim FolderPath
'Tabed to show relation.
Dim FileSystem
Dim Drives
Dim Drive
Dim Folders
Dim Folder
Dim SubFolders
Dim SubFolder
Dim Files
Dim File

Dim BgColor, BackgroundColor


'For anything on this page to work, the user must have the run-time
'dll's installed on the server. Lets try to create the object
'and see what happends.
Set FileSystem = Server.CreateObject("Scripting.FileSystemObject")

'Get File List Location
FolderPath = Request.QueryString("FolderPath")

If FolderPath = "" Then
'Not folder path specified. Lets use the one that this script is
'located in.
FolderPath = Request.ServerVariables("PATH_TRANSLATED")
End If

'Remove any files that are included as the path.
FolderPath = ParseFolder(FolderPath)

ScriptFolder = ParseFolder(Request.ServerVariables("PATH_TRANSLATED")) & "images\"

%>


Remote Explorer




<table width="100%" cellpadding="0" cellspacing="0" border="0">



   
<img src="images/_drive.gif" width="16" height="16" border="0" alt="Drive">
<input Class="Go" type="submit" value="Go">


   Address: 


" style="width:100%">


<input Class="Go" type="submit" value="Go">





<%
'Now that the user has a way to escape if an error occurs, let's
'create our objects.
Set Folder = FileSystem.GetFolder(FolderPath)
Set SubFolders = Folder.SubFolders
Set Files = Folder.Files
%>

<table cellpadding="0" cellspacing="0" border="0" width="100%">

Name 
Size  
Type 
Modified 
Attributes  


<%
If Not Folder.IsRootFolder Then
BgToggle
%>

">
?FolderPath=<%=Server.URLPathEncode(Folder.Drive & "\")%>">
<%=Icon("_drive.gif", "Top Level")%>
Top Level

 
"> 
"> 
"> 
"> 

<%BgToggle%>

">
?FolderPath=<%=Server.URLPathEncode(Folder.ParentFolder)%>">
<%=Icon("_up1level.gif", "Up One Level")%>
Up One Level

 
"> 
"> 
"> 
"> 

<%End If%>

<%
For Each SubFolder In SubFolders
BgToggle
%>

" title="<%=SubFolder.Name%>">
Response.Write _
Request.ServerVariables("SCRIPT_NAME") & _
"?FolderPath=" & _
Server.URLPathEncode(FolderPath & SubFolder.Name & "\")
%>"><%=Icon("_folder.gif", "Folder")%><%=SubFolder.Name%>

 
"> 
"><%=SubFolder.Type%> 
"><%=SubFolder.DateLastModified%> 
" align="right" class="Attributes"><%=Attributes(SubFolder.Attributes)%> 

<%Next%>

<%
For Each File In Files
BgToggle
Ext = FileExtension(File.Name)
%>

" title="<%=File.Name%>">
<%=Icon("ext_" & Ext & ".gif", Ext)%>
&thepath=<%=FolderPath%><%=File.Name%>"><%=File.Name%> OR Read:&thepath=<%=FolderPath%><%=File.Name%>"><%=File.Name%>

" align="right"><%=Int(File.Size * .01)%>KB  
"><%=File.Type%>
"><%=File.DateLastModified%>
" align="right" Class="Attributes"><%=Attributes(File.Attributes)%> 

<%Next%>





<%
' Routines --------------------------------------------------------------------

Private Function ConvertBinary(ByVal SourceNumber, ByVal MaxValuePerIndex, ByVal MinUpperBound, ByVal IndexSeperator)
Dim lsResult
Dim llTemp
Dim giCount
MaxValuePerIndex = MaxValuePerIndex + 1 '(1 Based Calculations)
'Find UpperBound if Minimum Upper Bound Isn't High enough
Do While Int(SourceNumber / (MaxValuePerIndex ^ MinUpperBound)) > (MaxValuePerIndex - 1)
MinUpperBound = MinUpperBound + 1
Loop
For giCount = MinUpperBound To 0 Step -1
'Get value of current index
llTemp = Int(SourceNumber / (MaxValuePerIndex ^ giCount))
'Add New Number to result
lsResult = lsResult & CStr(llTemp)
'Add Seperator?
If giCount > 0 Then lsResult = lsResult & IndexSeperator
SourceNumber = SourceNumber - (llTemp * (MaxValuePerIndex ^ giCount))
Next
ConvertBinary = lsResult
End Function
'------------------------------------------------------------------------------
Private Sub BgToggle()
BackgroundColor = Not(BackgroundColor)
If BackgroundColor Then
BgColor = "#efefef"
Else
BgColor = "#ffffff"
End If
End Sub
'------------------------------------------------------------------------------
Private Function Attributes(AttributeValue)
Dim lvAttributes
Dim lsResult
lvAttributes = Split(ConvertBinary(AttributeValue, 1, 7, ","), ",")
If lvAttributes(0) = 1 Then lsResult = "R" 'ReadOnly?
If lvAttributes(1) = 1 Then lsResult = lsResult & "H" 'Hidden?
If lvAttributes(2) = 1 Then lsResult = lsResult & "S" 'System?
If lvAttributes(5) = 1 Then lsResult = lsResult & "A" 'Archive?
Attributes = lsResult
End Function
'------------------------------------------------------------------------------
Private Function FileExtension(FileName)
Dim lsExt
Dim liCount
For liCount = Len(FileName) To 1 Step -1
If Mid(FileName, liCount, 1) = "." Then
lsExt = Right(FileName, Len(FileName) - liCount)
Exit For
End If
Next
If Not FileSystem.FileExists(ScriptFolder & "ext_" & lsExt & ".gif") Then
'We don't have an icon - show the default "unknown" icon.
lsExt = ""
End If
FileExtension = lsExt
End Function
'------------------------------------------------------------------------------
Private Function ParseFolder(PathString)
Dim liCount
If Right(PathString, 1) = "\" Then
ParseFolder = PathString
Else
For liCount = Len(PathString) To 1 Step -1
If Mid(PathString, liCount, 1) = "\" Then
ParseFolder = Left(PathString, liCount)
Exit For
End If
Next
End If
End Function
'------------------------------------------------------------------------------
Private Function Icon(Src, Alt)
Icon = _
"<img src=""images/" & Src & """ alt=""" & Alt & """" & _
" width=""16"" height=""16"" border=""0"">"
End Function
'------------------------------------------------------------------------------
%> <--- downloadfile.asp --> <%

call downloadFile(Request("file"))

function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------
mypath = Request.QueryString("thepath")

' get full path of specified file
strFilename = mypath


' clear the buffer
Response.Buffer = True
Response.Clear

' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

' set as binary
s.Type = 1

' load in the file
on error resume next


' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("

Error:

" & strFilename & " does not exist

")
Response.End
end if


' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size


s.LoadFromFile(strFilename)
if err then
Response.Write("

Error:

" & err.Description & "

")
Response.End
end if

' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush


' tidy up
s.Close
Set s = Nothing


end function

%> <-- read_text.asp -->



<%
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objTextStream
dim mypath
mypath = Request.QueryString("thepath")

' get full path of specified file
strFilename = mypath

const fsoForReading = 1

If objFSO.FileExists(strFilename) then
'The file exists, so open it and output its contents
Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
Response.Write "

" & objTextStream.ReadAll & "
"
objTextStream.Close
Set objTextStream = Nothing
Else
'The file did not exist
Response.Write strFileName & " was not found."
End If

'Clean up
Set objFSO = Nothing
%>

Views 5181 Downloads 1578

Classic ASP File System
JeffSmith
26
Revisions

v1.0