/**
* Parse FTP-connection string
*
* @param string $url like ftp://user:password@host:port/path/
* @return array hash(login, password, host, port, path)
*/
function parseFtpUrl($url) {
$result = array(
'login' => 'anonymous',
'password' => 'nobody@nobody.com',
'host' => '',
'port' => 21,
'path' => '',
);
if (preg_match('#^ftp://([^:@]+)?(:([^@]+))?@?([^:/]*)(:([^/]+))?(/(.*))?$#i', $url, $m)) {
if (!empty($m[1])) $result['login'] = $m[1];
if (!empty($m[3])) $result['password'] = $m[3];
if (!empty($m[4])) $result['host'] = $m[4];
if (!empty($m[6])) $result['port'] = $m[6];
if (!empty($m[8])) $result['path'] = rtrim($m[8], '/');
}
return $result;
}