×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: Pascual Muñoz
Added: Mar 11, 2017 7:44 AM
Views: 6
extrae parametros de una uri y devuelve una conexión
  1.     private function getFtpConnection ($uri)
  2.     {
  3.         // Split FTP URI into:
  4.         // $match[0] = ftp://username:password@sld.domain.tld/path1/path2/
  5.         // $match[1] = ftp://
  6.         // $match[2] = username
  7.         // $match[3] = password
  8.         // $match[4] = sld.domain.tld
  9.         // $match[5] = /path1/path2/
  10.         preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $uri, $match);
  11.         $this->destParamContainer = $match;
  12.  
  13.         // Set up a connection
  14.         $conn = ftp_connect($match[1].$match[4].$match[5]);
  15.  
  16.         // Login
  17.         if (ftp_login($conn, $match[2], $match[3])) {
  18.             // Change the dir
  19.             ftp_chdir($conn, $match[5]);
  20.  
  21.             // Return the resource
  22.             return $conn;
  23.         }
  24.  
  25.         // Or retun null
  26.         return null;
  27.     }