这只会创建一个空文件..文件中没有内容
$host = 'domain.com';
$pass = 'xxx';
$remote = 'sftp://var/www/test.txt';
$local = 'C:\wamp\www\test.txt';
$curl = curl_init();
$file = fopen($local, 'w');
curl_setopt($curl, CURLOPT_URL, $remote);
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curl, CURLOPT_USERPWD, "root:$pass");
curl_setopt($curl, CURLOPT_FILE, $file);
curl_exec($curl);
curl_close($curl);
fclose($file);
$host = 'domain.com';
$pass = 'xxx';
$remote = "sftp://root:$pass@$host/var/www/test.txt";
$local = 'C:\wamp\www\test.txt';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $remote);
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curl, CURLOPT_USERPWD, "root:$pass");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
file_put_contents($local, curl_exec($curl));
curl_close($curl);
答案 0 :(得分:1)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$d = curl_exec($curl);
// data is in $d var, write it somewhere ;)
$local = "/tmp/myfile.txt";
file_put_contents($local, $d);