From my php script, i need to be able to upload a csv file to a remote server via sftp. I followed the accepted answer from this question:
Here's what my code looks like
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ch = curl_init();
$localfile = 'export-3.csv';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'sftp://user:[email protected]/'.$localfile);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
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 = 'File upload error.';
}
echo $error.' '.$error_no;
?>
The output was
Notice: Use of undefined constant CURLOPT_PROTOCOLS - assumed 'CURLOPT_PROTOCOLS' in /home/john/public_html/test/test.php on line 9
Notice: Use of undefined constant CURLPROTO_SFTP - assumed 'CURLPROTO_SFTP' in /home/john/public_html/test/test.php on line 9
File upload error.1
I am using curl libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10 . When I did a sudo apt-get install php5-curl, the computer said i had the most recent version.
What am I doing wrong? How do i sftp upload my files to a remote server from php?
system('sftp to_server....')
. Checkman sftp
– Miltonmilty