/    Sign up×
Community /Pin to ProfileBookmark

[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 [B]ftp_nlist[/B] 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 [B]is_dir[/B] nor [B]is_file[/B] nor [B]file_exists[/B] because I can’t get the real path (both absolute and relative) to them. I thought on using [B]ftp_size[/B] but I’m not sure if it’s ok and if there’s a better way.

Any suggestions appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 23.2011 — 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).
[code=php]
$contents = ftp_list($ftp, '-F relative/directory');
[/code]

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. ?
Copy linkTweet thisAlerts:
@JazztronikauthorMay 24.2011 — I will try those options. Thanks a lot! ?
×

Success!

Help @Jazztronik spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...