cvs: pear /Net_FTP/Net FTP.php /Net_FTP/tests Net_FTPTest.php

[email protected] ("Jorrit Schippers")
Newsgroups php.pear.cvs
Message-ID <cvsjschippers1208899401@cvsserver>
jschippers		Tue Apr 22 21:23:21 2008 UTC

  Modified files:              
    /pear/Net_FTP/Net	FTP.php 
    /pear/Net_FTP/tests	Net_FTPTest.php 
  Log:
  Implemented Request #13104: connect() <> $this->handle in login()
  
http://cvs.php.net/viewvc.cgi/pear/Net_FTP/Net/FTP.php?r1=1.65&r2=1.66&diff_format=u
Index: pear/Net_FTP/Net/FTP.php
diff -u pear/Net_FTP/Net/FTP.php:1.65 pear/Net_FTP/Net/FTP.php:1.66
--- pear/Net_FTP/Net/FTP.php:1.65	Tue Apr 22 21:01:31 2008
+++ pear/Net_FTP/Net/FTP.php	Tue Apr 22 21:23:20 2008
@@ -20,7 +20,7 @@
  * @author    Jorrit Schippers <[email protected]>
  * @copyright 1997-2008 The PHP Group
  * @license   http://www.php.net/license/3_0.txt PHP License 3.0
- * @version   CVS: $Id: FTP.php,v 1.65 2008/04/22 21:01:31 jschippers Exp $
+ * @version   CVS: $Id: FTP.php,v 1.66 2008/04/22 21:23:20 jschippers Exp $
  * @link      http://pear.php.net/package/Net_FTP
  * @since     File available since Release 0.0.1
  */
@@ -602,10 +602,13 @@
     /**
      * This holds the handle for the ftp-connection
      *
+     * If null, the connection hasn't been setup yet. If false, the connection
+     * attempt has failed. Else, it contains an ftp resource.
+     *
      * @access  private
      * @var     resource
      */
-    var $_handle;
+    var $_handle = null;
 
     /**
      * Contains the timeout for FTP operations
@@ -743,6 +746,7 @@
         $handle = @ftp_connect($this->getHostname(), $this->getPort(),
                                $this->_timeout);
         if (!$handle) {
+            $this->_handle = false;
             return $this->raiseError("Connection to host failed",
                                      NET_FTP_ERR_CONNECT_FAILED);
         } else {
@@ -764,6 +768,7 @@
             return PEAR::raiseError('Disconnect failed.',
                                     NET_FTP_ERR_DISCONNECT_FAILED);
         }
+        $this->_handle = null;
         return true;
     }
 
@@ -772,6 +777,8 @@
      * password in this method. If you specify it, the values will be taken into 
      * the corresponding attributes, if do not specify, the attributes are taken.
      *
+     * If connect() has not been called yet, a connection will be setup
+     *
      * @param string $username (optional) The username to use 
      * @param string $password (optional) The password to use
      *
@@ -781,6 +788,13 @@
      */
     function login($username = null, $password = null)
     {
+        if ($this->_handle === null) {
+            $res = $this->connect();
+            if (PEAR::isError($res)) {
+                return $res;
+            }
+        }
+        
         if (!isset($username)) {
             $username = $this->getUsername();
         } else {
http://cvs.php.net/viewvc.cgi/pear/Net_FTP/tests/Net_FTPTest.php?r1=1.14&r2=1.15&diff_format=u
Index: pear/Net_FTP/tests/Net_FTPTest.php
diff -u pear/Net_FTP/tests/Net_FTPTest.php:1.14 pear/Net_FTP/tests/Net_FTPTest.php:1.15
--- pear/Net_FTP/tests/Net_FTPTest.php:1.14	Tue Apr 22 20:40:15 2008
+++ pear/Net_FTP/tests/Net_FTPTest.php	Tue Apr 22 21:23:20 2008
@@ -26,7 +26,7 @@
  * @author    Tobias Schlitt <[email protected]>
  * @copyright 1997-2008 The PHP Group
  * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version   CVS: $Id: Net_FTPTest.php,v 1.14 2008/04/22 20:40:15 jschippers Exp $
+ * @version   CVS: $Id: Net_FTPTest.php,v 1.15 2008/04/22 21:23:20 jschippers Exp $
  * @link      http://pear.php.net/package/Net_FTP
  * @link      http://www.phpunit.de PHPUnit
  * @since     File available since Release 1.3.3
@@ -99,13 +99,6 @@
         }
         
         $this->ftp = new Net_FTP(FTPHOST, FTPPORT, 30);
-        $res       = $this->ftp->connect();
-        
-        if (PEAR::isError($res)) {
-            $this->setupError = 'Could not connect to the FTP server';
-            $this->ftp        = null;
-            return;
-        }
         
         $res = $this->ftp->login(FTPUSER, FTPPASSWORD);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.