我試圖做一個簡單的cURL文件從一臺服務器上傳到另一臺服務器。問題是我從cUrl錯誤代碼中獲得錯誤#3:URL格式不正確。PHP cURL錯誤URL格式不正確
我已將網址複製到我的瀏覽器並登錄到ftp站點,沒有任何問題。我還驗證了正確的格式,並在網站和本網站上搜索了一個沒有任何成功的答案。
下面的代碼:
$ch = curl_init();
$localfile = '/home/httpd/vhosts/homeserver.com/httpdocs/admin.php';
echo $localfile; //This reads back to proper path to the file
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://username:[email protected]/');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'Upload error:'.$error_no ;//Error codes explained here http://curl.haxx.se/libcurl/c/libcurl-errors.html';
}
echo $error;
我也試過這樣:
curl_setopt($ch, CURLOPT_URL, 'ftp://199.38.215.1xx/');
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
我仍然得到錯誤#3。
任何想法?
PHP內置的FTP功能可能比捲曲更好地工作。 –