2012-03-15 87 views
1

我需要在使用php cURL下載後重命名文件。使用php cURL移動ftp站點上的文件

這是我有:

$localFile = fopen($fileName, 'w'); 

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_FILE, $localFile); 
    curl_setopt($curl, CURLOPT_USERPWD, "$ftpUsername:$ftpPassword"); 
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile", "RNTO $remoteFile.downloaded")); 

    curl_exec($curl) === false) { 
     throw new Exception(curl_error($curl)); 
    } 

如果我刪除CURLOPT_POSTQUOTE一部分,該文件下載的罰款。我也試過postquote陣列的幾個不同的組合:

curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile RNTO $remoteFile.downloaded")); 
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile", "-RNTO $remoteFile.downloaded")); 
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile -RNTO $remoteFile.downloaded")); 
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("rename $remoteFile $remoteFile.downloaded")); 

我已經得到的樣子錯誤:

ERROR : QUOT string not accepted: -RNFR $remoteFile -RNTO $remoteFile.downloaded 

回答

3

如果有人在這裏找到自己的未來。

我的問題是,$remoteFile決心像/remote_folder/remote_file.txt,但因爲我的FTP連接已經包含的文件夾,像ftp://www.example.com/remote_folder/remote_file.txt,我不應該在RNFRRNTO到指定的文件夾。

+0

最後,添加到「CURLOPT_POSTQUOTE」列表中的** two **命令是:'RNFR remote_file.txt'和'RNTO remote_file_downloaded.txt'。 – cesargastonec 2015-03-06 18:41:54