Browse Source

- Fix for FSM 1.2
- asynchronism fix: check whether f_fp is still a resource before using it to display the progress bar

Frederic G. Marand 17 years ago
parent
commit
fe29286021
1 changed files with 12 additions and 8 deletions
  1. 12 8
      u_ftp.php

+ 12 - 8
u_ftp.php

@@ -4,7 +4,9 @@
  * (c) 2006 Ouest Systèmes Informatiques (OSI)
  * Licensed under the CeCILL 2.0 license
  *
- * $Id: u_ftp.php,v 1.2 2006-12-03 23:23:38 marand Exp $
+ * $Id: u_ftp.php,v 1.3 2007-04-28 20:03:40 marand Exp $
+ *
+ * @todo redo to take advantage of the new FSM 1.2 features to reduce the code
  */
 
 require_once('u_fsm.php');
@@ -268,13 +270,13 @@ class ftp_client extends fsm
    */
   protected function f_check_params()
     {
-    // echo func_name() . "\n";
     $ret = isset($this->f_host)
       && isset($this->f_user)
       && isset($this->f_pass)
       && isset($this->f_file)
       && isset($this->f_localfile)
       ;
+    // echo func_name() . ", ret = " . ($ret ? 'TRUE' : 'FALSE') . PHP_EOL;
     return $ret;
     }
 
@@ -298,7 +300,7 @@ class ftp_client extends fsm
    */
   protected function f_close()
     {
-    echo func_name() . "\n";
+    // echo func_name() . "\n";
     $ret = ftp_close($this->f_conn);
     return $ret;
     }
@@ -321,7 +323,7 @@ class ftp_client extends fsm
    */
   protected function f_get()
     {
-    echo func_name() . "\n";
+    // echo func_name() . "\n";
     $this->f_fp = fopen($this->f_localfile, "wb");
     if (!is_resource($this->f_fp))
       {
@@ -382,7 +384,7 @@ class ftp_client extends fsm
    */
   public function close()
     {
-    echo func_name() . "\n";
+    // echo func_name() . "\n";
     return $this->apply_event('close');
     }
 
@@ -392,7 +394,7 @@ class ftp_client extends fsm
    */
   public function get()
     {
-    echo func_name() . "\n";
+    // echo func_name() . "\n";
     return $this->apply_event('get');
     }
 
@@ -405,12 +407,14 @@ class ftp_client extends fsm
   public function cont() // continue is a php reserved word
     {
     // echo func_name() . "\n";
-    return $this->apply_event('continue');
+    $ret = $this->apply_event('continue');
+    $ret = $ret->fsm_state;
+    return $ret;
     }
 
   public function get_progress()
     {
-    if (!$this->f_state == 'active')
+    if ((!$this->f_state == 'active') || (!is_resource($this->f_fp)))
       $ret = 0;
     else
       {