www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Best way to check whether a file is file or directory when using FTP

  1. #1
    Join Date
    Jul 2007
    Posts
    245

    resolved [RESOLVED] Best way to check whether a file is file or directory when using FTP

    I have to loop through a list of directories to look for a file, but I cannot use the filesystem functions because the list is retrieved from an FTP connection and a priori I wouldn't have to know the real path to the file. So, I use ftp_nlist to retrieve an array with all the directories within a relative path, but I only want to do something with the subdirectories: to check whether a file exists within any of them (just one level deep needed), and discard the files and current or parent directories.

    As far as I know I cannot use functions like is_dir nor is_file nor file_exists because I can't get the real path (both absolute and relative) to them. I thought on using ftp_size but I'm not sure if it's ok and if there's a better way.

    Any suggestions appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    You could try adding the -F flag, which if it works will append a "/" to the end of directory names (and may append "*" to end of executables).
    PHP Code:
    $contents ftp_list($ftp'-F relative/directory'); 
    Alternatively you could use ftp_rawlist() instead, and parse the the beginning of each entry where it lists the file type and permissions info.

    I won't guarantee, however, that you'll get the same results from different target hosts.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2007
    Posts
    245

    resolved

    I will try those options. Thanks a lot!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles