Reputation:
Examples:
awesome_dksd.php
awesome_dfkdde.php
dklf_dlsfd.php
Path to examples: public_html/folder/
How can I search in side of that ftp using php for the files that start with awesome_ I am able to connect via ftp_connect()
I just cant find a function or any way to search inside a ftp for a file that begins with awesome_
?
Thank you
Upvotes: 0
Views: 770
Reputation: 1
you can try something similiar (tweak to taste and php version)
$ftpStream = ftp_connect (...);
// file listing
$files = ftp_nlist ( $ftpStream , string $directory );
// filters array with function that search position of string
$array = array_filter($array, function($value) {
return !(strpos($value, 'awesome') > 0);
});
Regards.
Upvotes: 0
Reputation: 20081
Get a list of all files using ftp_nlist
http://php.net/manual/en/function.ftp-nlist.php
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");
Then just loop over the $contents
with foreach
or use your favourite regex method to filter out anything that doesnt start with awesome_!
Upvotes: 1