Link to home
Start Free TrialLog in
Avatar of djdidge
djdidge

asked on

FTP ... check if dir exists

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
Avatar of iamkalyang
iamkalyang

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 ??

Avatar of djdidge

ASKER

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).
ASKER CERTIFIED SOLUTION
Avatar of adit_2k
adit_2k

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djdidge

ASKER

thanks for that.... but my major issue is checking the existance of a dir on the ftp
this code will check the existence od "mydir", before proceeding

you can validate the value of variable f
Avatar of Mark Franz
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


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/

Avatar of djdidge

ASKER

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

Thanks!!
"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
%>
Avatar of djdidge

ASKER

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
Avatar of djdidge

ASKER

u were first
That answer only counts files... you had a 2 part question.