codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Lisitng files from remote server  chandhru at 21:37 on Monday, February 23, 2004
 

In searching the web for listing files from remote server, I found the link form codetoad. The solution by Mr.Troy is as follows

For example:

C:
K:\music
\\127.0.0.1\files

Save this code as a new ASP file, then navigate to it to see it run. It will show a list of folders and files in your webserver's root.

<%
rootFolder = Server.MapPath("/index.html")
set filesys = server.CreateObject("scripting.filesystemobject")
set folder = filesys.GetFolder(rootFolder)
set subfolders = folder.SubFolders
set files = folder.Files
folderCount = subfolders.Count
fileCount = files.Count

Response.Write("<table>" & vbcrlf & _
"<tr>" & vbcrlf & _
"<th>Folder Name</th>" & _
"<th>Size</th>" & _
"<th>Modified Date</th>" & _
"</tr>" & vbcrlf)

for each subfolder in subfolders
sizeWrk = Round(subfolder.Size / 1024,0)
if sizeWrk < 1 then sizeWrk = 1
sizeWrk = formatnumber(sizeWrk,0) & " KB"
Response.Write("<tr>" & vbcrlf & _
"<td>" & subfolder.Name & "</td>" & _
"<td>" & sizeWrk & "</td>" & _
"<td>" & subfolder.DateLastModified & "</td>" & _
"</tr>" & vbcrlf)
next

Response.Write("</table><hr>" & vbcrlf)

Response.Write("<table>" & vbcrlf & _
"<tr>" & vbcrlf & _
"<th>File Name</th>" & _
"<th>Size</th>" & _
"<th>Modified Date</th>" & _
"</tr>" & vbcrlf)

for each file in files
sizeWrk = Round(file.Size / 1024,0)
if sizeWrk < 1 then sizeWrk = 1
sizeWrk = formatnumber(sizeWrk,0) & " KB"
Response.Write("<tr>" & vbcrlf & _
"<td>" & file.Name & "</td>" & _
"<td>" & sizeWrk & "</td>" & _
"<td>" & file.DateLastModified & "</td>" & _
"</tr>" & vbcrlf)
next

Response.Write("</table><hr>" & vbcrlf)
%>

I tried running this code. this code works fine with the following

"C:\" or "\" or "\\"

but whenever i give the rootfolder to something as

"\\127.0.0.1\ " or "\\localhost\" it gives path not found error. As I have to use UNC to list the files from remote server , do I need to setup a different permission in order for this code to work.



  Re: Lisitng files from remote server  Troy Wolf at 21:53 on Monday, February 23, 2004
 

Try "\\127.0.0.1\c$". That should equal the root of your C: Drive. Your script will need permissions to that administrative share, though. This may be the IUSR account or a specific user account if you are authenticating to your script.

"\\127.0.0.1\" does not equal anything in the filesystem--it equals a computer.

You say using just "C:\" works. So why now just use that?
Troy Wolf: site expert
Shiny Solutions


  Re: Lisitng files from remote server  chandhru at 14:45 on Tuesday, February 24, 2004
 

Actually I am trying to retrieve files from the remote server and compare them with the database in my Desktop. In order to retrieve those files I need to use UNC . after deleting the IUSR_local I am able to view the files using \\127.0.0.1\c$. but still I am having problems in accessing the files from remote server.


I really dont know where I am going wrong.

  Re: Lisitng files from remote server  Troy Wolf at 15:40 on Tuesday, February 24, 2004
 

I'm going to try to explain this one more time (I'm not doing a good job of it I know.) You cannot use the filesystem object against a remote server.

You can only use it against servers that you have direct file access. For example, if you cannot access that server's harddrive(s) using \\servername\drive\folder\, then you cannot use the filesystem object.

My web server is in a hosting facility. I have FTP access to the server, but I do not have direct filesystem access. i.e., I cannot browse my Network Neighborhood to get to the webserver computer. So I cannot use the filesystem object in script on my local computer to access the drive system on that webserver.

What you CAN do, though, is have a script that runs locally ON the remote server. Have it return the results you want to compare to your local filesystem. This is a bit advanced, but you can have an ASP that runs LOCALLY on the remote server. Your local machine can have a script that calls that remote script, gets the results, then use the filesystem object locally to compare your local system with the results from the remote. (Tip: Use Server.XMLHTTP to call a remote ASP script from an ASP script. There are threads here on CodeToad that explain how to do this -- it is a common technique used in screen-scraping.)

I would first explore using scripted FTP to do what you want. It depends on what exactly you want to do. With an inexpensive FTP ASP Component, you can access the remote filesystem and iterate through the folders and files. Not as robust as the filesystem object, but depends on what you need to do.
Troy Wolf: site expert
Shiny Solutions









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Re: ASP.NET web controls
•  Re: JavaSript Problem In Mac Safari Browser
•  Re: DHTML div positionning Problem
•  Convert script to NS6 compatible - Please Help!
•  Print .doc file from the website using System.Diagnostics.Process
•  Re: Fullscreen code
•  Re: iframe targeting
•  Excel n ASP


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005