I use a piece of excellent PHP code to upload files to FTP via cURL. It has served me well until today.
It returns a curl # 3 error when I execute it. Intepretation of error: CURLE_URL_MALFORMAT (3): The URL was not formatted correctly. I realized that this is because the password contains special characters. Password contains '<' for example R3lHK2A9 <1 This code works in the past when all passwords consist only of letters and numbers.
I tried using escapeshellarg() , urlencode() and escapeshellcmd() for the password .... in vain. Did I miss something?
Can you guys help?
<?php $ch = curl_init(); $localfile = "test.tar"; $fp = fopen($localfile, 'r'); curl_setopt($ch, CURLOPT_URL, 'ftp://username: [email protected] /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; ?>
source share