M
M
mikle542015-02-07 11:40:10
PHP
mikle54, 2015-02-07 11:40:10

Square brackets in paths when working via FTP via PHP?

Get a list of files in a directory. I use:

$conn_id = ftp_connect('ftp-serv');
$login_result = ftp_login($conn_id, 'login', 'pass');
$buff = ftp_rawlist($conn_id,$path);
print_r($buff);
ftp_close($conn_id);
(php 5.3.3)
Only works if there are no square brackets ([]) in the path. If present in $path (e.g. 'home/['), ftp_rawlist($conn_id,$path) is an empty array (regardless of whether the directory exists), not a list of files, or an error. Tell me how to escape these characters, or what needs to be done for correct operation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2015-02-07
@mikle54

Mb help screening?
Then curl should help:

$login = '';
$pass = '';
$server = 'ftp.com';
$ch = curl_init('ftp://'.$login.':'.$pass.'@'.$server.'/dir[/');
curl_setopt($ch, CURLOPT_FTPLISTONLY, true); //Вернёт список директорий
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$dirs = curl_exec($ch);
var_dump(explode(PHP_EOL,$dirs));

Checked - works great

I
index0h, 2015-02-07
@index0h

Rename directories, or create symlinks with normal paths.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question