note 95186 added to function.ftp-connect
| From: | michaelatnoemaildotorg at osu1 dot php dot net | Date: | Thu, 17 Dec 2009 10:38:11 +0000 |
| Subject: | note 95186 added to function.ftp-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164071@lists.php.net to get a copy of this message | ||
There were some mistakes in sean at boyercentral dot net's ftp connection function. The regular
expression doesn't split the uri like shown in the example (the array element containing the
ftp protocol prefix is missing).
Plus, adding the ftp prefix oder directory adress to the host adress given to the ftp_connect
function may result in an error.
I adjusted his function to work properly:
<?php
function getFtpConnection($uri)
{
// Split FTP URI into:
// $match[0] = ftp://username:password@sld.domain.tld/path1/path2/
// $match[1] = username
// $match[2] = password
// $match[3] = sld.domain.tld
// $match[4] = /path1/path2/
preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $uri,
$match);
// Set up a connection
$conn = ftp_connect($match[3]);
// Login
if (ftp_login($conn, $match[1], $match[2]))
{
// Change the dir
ftp_chdir($conn, $match[4]);
// Return the resource
return $conn;
}
// Or retun null
return null;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.172.224.95
----
Manual Page -- http://www.php.net/manual/en/function.ftp-connect.php
Edit -- https://master.php.net/note/edit/95186
Del: integrated -- https://master.php.net/note/delete/95186/integrated
Del: useless -- https://master.php.net/note/delete/95186/useless
Del: bad code -- https://master.php.net/note/delete/95186/bad+code
Del: spam -- https://master.php.net/note/delete/95186/spam
Del: non-english -- https://master.php.net/note/delete/95186/non-english
Del: in docs -- https://master.php.net/note/delete/95186/in+docs
Del: other reasons-- https://master.php.net/note/delete/95186
Reject -- https://master.php.net/note/reject/95186
Search -- https://master.php.net/manage/user-notes.php