I'm trying to get a .csv file from a SFTP server, and then save it locally. I'm using the following code but it doesn't seem to be working.
<?php
$user = 'username';
$pass = 'password';
$host = 'order.domain.com';
$file = 'filename.csv';
$remote = "sftp://$user:$pass@$host/$file";
$local = getcwd() . '/' . $file;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $remote);
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curl, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
file_put_contents($local, curl_exec($curl));
curl_close($curl);
?>
It seems to be creating the filename.csv
file in the current working directory, however it is blank.
It appears maybe the curl isn't connecting to the remote server? Maybe the curl isnt set up for SFTP?