We help IT Professionals succeed at work.

FTP ... check if dir exists

djdidge
djdidge asked
on
how can I check if a directory exists on an FTP svr.
And how can I get a file count of files in that dir?

Thanks
Comment
Watch Question

where is the FTP server running. in the same place as web server. what is the location of both..

do u want to check using ASP ??

Author

Commented:
ftp server is on the same LAN as my web server... yes I'd like to check if the dir exists with ASP (FSO doesn't work, or atleast I can't get it to).
Commented:
<%
set fso2 = server.CreateObject("scripting.filesystemobject")

strdir = "mydir"
strpath2 = server.MapPath(strdir)
set f = fso2.GetFolder(strpath2)

set fc = f.files
i=0

for each f1 in fc
     ReDim Preserve myArray(i)
     myArray(i) = f1.name
     i=i+1
next

response.write i 'Count of files
%>

Author

Commented:
thanks for that.... but my major issue is checking the existance of a dir on the ftp

Commented:
this code will check the existence od "mydir", before proceeding

you can validate the value of variable f
Mark FranzProject Manager
BRONZE EXPERT

Commented:
FolderExists Method
Returns True if a specified folder exists; False if it does not.

object.FolderExists(folderspec)

Arguments
object

Required. Always the name of a FileSystemObject.

folderspec

Required. The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder.

Remarks
The following example illustrates use of the FolderExists method:

Function ReportFolderStatus(fldr)
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FolderExists(fldr)) Then
      msg = fldr & " exists."
   Else
      msg = fldr & " doesn't exist."
   End If
   ReportFolderStatus = msg
End Function

Files Collection
Collection of all File objects within a folder.

Remarks
The following code illustrates how to get a Files collection and iterate the collection using the For Each...Next statement:

Function ShowFolderList(folderspec)
   Dim fso, f, f1, fc, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(folderspec)
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name
      s = s & "<BR>"
   Next
   ShowFolderList = s
End Function


Commented:
Try etiveFTP component. It provides "List" method, which returns file & directories list on remote FTP server.

Demo could be downloaded from http://www.etive.com/software/etiveftp/

Author

Commented:
thanks all... I currently have a development rush on... as soon as that is sorted I shall evaluate your suggestions...

Thanks!!
Mark FranzProject Manager
BRONZE EXPERT

Commented:
"Use the FSO Luke..."

It really doesn't get any easier than this;

<%
Dim fso, msg, fldr
fldr = "c:\inetpub\ftproot\test"
  Set fso = CreateObject("Scripting.FileSystemObject")
  If (fso.FolderExists(fldr)) Then
     Response.Write fldr & " exists."
  Else
     Response.Write fldr & " doesn't exist."
  End If
  ReportFolderStatus = msg
%>

Author

Commented:
I have just looked briefly at your suggestions... just to reaffirm my issue,

The FTP server that i need to check if a directory exists isn't the machine that the script is to run on...

ie question re-word:

I need to check if a directory exists on a FTP server from a client machine
....
If your suggestions fit this profile then i appologise!

Gary

Author

Commented:
u were first
Mark FranzProject Manager
BRONZE EXPERT

Commented:
That answer only counts files... you had a 2 part question.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.