<?php
$strServer = "****";
$strServerPort = ****;
$strServerUsername = "****";
$strServerPassword = "****";
//connect to server
$resConnection = @ssh2_connect($strServer, $strServerPort);
if(@ssh2_auth_password($resConnection, $strServerUsername, $strServerPassword)){
//init SFTP
$resSFTP = @ssh2_sftp($resConnection);
$filename = 'C:\Users\Administrator\Documents'.time().'.csv';
$strData = file_get_contents("ssh2.sftp://{$resSFTP}/winchannel/20161218-DSR.CSV");
file_put_contents($filename, $strData);
} else {
echo "Unable to authenticate on server";
}
?>
文件在sftp上面以这种形式储存
没有使用过
ssh2_connect
,将file_get_contents
的url进行urlencode
试试,然后输出下$strData