FTP_DELETE不工作?

时间:2012-04-12 16:57:34

标签: php oop magento

嘿伙计们我的脚本在这里应该做一些东西然后删除一个文件,不幸的是我的文件永远不会取消链接。我想知道这可能是什么原因?权限是我唯一能想到的,或者输出缓冲区可能搞乱了?我真的不知道,但我会很感激如何处理它。有问题的是最后的IF()阻止。

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 个答案:

答案 0 :(得分:2)

答案是系统变量$remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file');设置为BOOL(false)