note 103431 added to function.ftp-connect

From: Date: Wed, 13 Apr 2011 03:21:15 +0000
Subject: note 103431 added to function.ftp-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-178785@lists.php.net to get a copy of this message
I really liked "sean at boyercentral dot net"'s reg_ex for splitting out the complete URI (with dir), but it had a few problems with the array positions... here is a revised edition: <?php function getFtpConnection($uri) { /* Split FTP URI into: array(5) { [0]=> string(48) "ftp://user:password@ftp.myftptest.com/remotedir/" [1]=> string(4) "user" [2]=> string(8) "password" [3]=> string(17) "ftp.myftptest.com" [4]=> string(11) "/remotedir/" } */ preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $uri, $uriArr); list($src,$usr,$pwd,$url,$dir) = $uriArr; // Set up a connection $conn = ftp_connect($url); // Login if (ftp_login($conn, $usr, $pwd)) { // Change the dir ftp_chdir($conn, $dir); // Return the resource return $conn; } // Or retun null return null; } ?> example usage: <?php $conn_rsrc = getFtpConnection('ftp://user:password@ftp.myftptest.com/remotedir/'); ?> ---- Server IP: 117.55.229.1 Probable Submitter: 203.59.102.142 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-connect.php Edit -- https://master.php.net/note/edit/103431 Del: integrated -- https://master.php.net/note/delete/103431/integrated Del: useless -- https://master.php.net/note/delete/103431/useless Del: bad code -- https://master.php.net/note/delete/103431/bad+code Del: spam -- https://master.php.net/note/delete/103431/spam Del: non-english -- https://master.php.net/note/delete/103431/non-english Del: in docs -- https://master.php.net/note/delete/103431/in+docs Del: other reasons-- https://master.php.net/note/delete/103431 Reject -- https://master.php.net/note/reject/103431 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178785) next »