2012-04-12 44 views
1

嗨我在這裏有我的腳本應該做一些東西然後刪除一個文件,偏偏我的文件從來沒有斷開鏈接。我想知道這可能是什麼原因?權限是我能想到的唯一的東西,或者輸出緩衝區搞亂了?我真的不知道,但希望得到一些關於如何處理它的建議。問題是,最後的IF()塊。FTP_DELETE不工作?

public function remoteFtp() { 
    $enabled = Mage::getStoreConfig('cataloginventory/settings/use_ftp'); 
    $remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file'); 
    if ($enabled == 0) { 
     return true; 
    } 

    $base_path = Mage::getBaseDir('base'); 


    $ftp_url = Mage::getStoreConfig('cataloginventory/settings/ftp_url'); 
    $ftp_user = Mage::getStoreConfig('cataloginventory/settings/ftp_user'); 
    $ftp_pass = Mage::getStoreConfig('cataloginventory/settings/ftp_password'); 
    $ftp_remote_dir = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_dir'); 
    $ftp_filename_filter = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_filename'); 

    $ftp_file = $base_path . '/edi/working/working.edi'; 

    $handle = fopen($ftp_file, 'w'); 
    $conn_id = ftp_connect($ftp_url); 

    ftp_login($conn_id, $ftp_user, $ftp_pass) or die("unable to login"); 

    if ($ftp_remote_dir) { 
     ftp_chdir($conn_id, $ftp_remote_dir); 
    } 

    //is there a file 
    $remote_list = ftp_nlist($conn_id, "."); 

    $exists = count($remote_list); 

    if ($exists > 0) { 
     $len = strlen($ftp_filename_filter) - 1; 


     foreach ($remote_list as $name) { 
      if (substr($ftp_filename_filter, 0, 1) == "*") { 

       if (substr($name, '-' . $len) == substr($ftp_filename_filter, '-' . $len)) { 
        $ftp_remote_name = $name; 
       } 
      } 
      if (substr($ftp_filename_filter, strlen($name) - 1) == "*") { 
       if (substr($ftp_filename_filter, 0, $len) == substr($name, 0, $len)) { 
        $ftp_remote_name = $name; 
       } 
      } 
      if ($ftp_filename_filter == $name) { 
       $ftp_remote_name = $name; 
      } 
     } 
    } 


    if (ftp_fget($conn_id, $handle, $ftp_remote_name, FTP_ASCII, 0)) { 
     echo "successfully written to $ftp_file <br />"; 
     if ($remove == 1) { 
      ftp_delete($conn_id, $ftp_remote_name); 
     } 
    } else { 
     echo "There was a problem while downloading $ftp_remote_name to $ftp_file <br />"; 
    } 

    ftp_close($conn_id); 
} 
+1

如果你想權限可能是問題,你檢查他們? – ceejayoz 2012-04-12 16:58:35

+1

當你嘗試使用GUI FTP客戶端手動執行時,它是否工作? – DaveRandom 2012-04-12 16:59:26

+0

@ceejayoz我沒有檢查權限,作爲ftp用戶他們在0777,它在GUI客戶端上工作,並且我使用確切的相同的憑據。 – ehime 2012-04-12 17:03:52

回答

2

答案是可變$remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file');系統設置爲布爾(假)