我试图做一个简单的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功能可能比卷曲更好地工作。 –