Created
January 14, 2015 14:50
-
-
Save ZiTAL/8c5652fef5400d870e1d to your computer and use it in GitHub Desktop.
php: ftp raw list desglosea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$params = array | |
( | |
'host' => '127.0.0.1', | |
'port' => 21, | |
'user' => 'ftpuser', | |
'passwd' => 'ftpuser' | |
); | |
$conn_id = ftp_connect($params['host'], $params['port']); | |
$login_result = ftp_login($conn_id, $params['user'], $params['passwd']); | |
if($login_result) | |
{ | |
$keys = array | |
( | |
1 => 'permissions', | |
2 => 'links', | |
3 => 'owner', | |
4 => 'group', | |
5 => 'size', | |
6 => 'date', | |
7 => 'filename' | |
); | |
// adibidez: 'drwx------ 3 999 1001 4096 Jan 14 11:00 public html'; | |
$regex = "/^([^\s+]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([\w]+\s+[0-9]+\s+[0-9\:]+)\s+([^$]+)$/"; | |
$contents = ftp_rawlist($conn_id, "."); | |
$resources = array(); | |
foreach($contents as $c) | |
{ | |
preg_match($regex, $c, $m); | |
if($m) | |
{ | |
$r = array(); | |
for($i=1;$i<count($m);$i++) | |
$r[$keys[$i]] = $m[$i]; | |
// hutsuneak hutsune bakar batean bihurtu | |
$r['date'] = preg_replace("/\s+/", ' ', $r['date']); | |
$resources[] = $r; | |
} | |
} | |
print_r($resources); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment