I've been using a piece of nifty PHP code to upload files to FTP via cURL. It has served me well until today.
It returns a curl error #3 when I execute it Intepretation of error: CURLE_URL_MALFORMAT (3) : The URL was not properly formatted. I figured it was because the password contains special characters. The password contains a '<' e.g. R3lHK2A9<1 This code works in the past where the passwords all consist of only letters and numbers.
I tried using escapeshellarg()
, urlencode()
and escapeshellcmd()
to the password....in vain. Am I missing something?
Can you guys help please?
<?php
$ch = curl_init();
$localfile = “test.tar”;
$fp = fopen($localfile, ‘r’);
curl_setopt($ch, CURLOPT_URL, ‘ftp://username:password@ftp.domain.com/public_html/filesfromscript/’.$localfile);
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) {
$message = ‘File uploaded successfully.’;
} else {
$message = “File upload error: $error_no. Error codes explained here http://curl.haxx.se/libcurl/c/libcurl-errors.html”;
}
echo $message;
?>