我试图使用
PHP从sftp服务器下载文件,但我找不到任何正确的文档来下载文件.
<?PHP
$strServer = "pass.com";
$strServerPort = "22";
$strServerUsername = "admin";
$strServerPassword = "password";
$resConnection = ssh2_connect($strServer,$strServerPort);
if(ssh2_auth_password($resConnection,$strServerUsername,$strServerPassword)) {
$resSFTP = ssh2_sftp($resConnection);
echo "success";
}
?>
打开SFTP连接后,下载文件需要做什么?
使用
phpseclib,a pure PHP SFTP implementation:
<?PHP
include('Net/SFTP.PHP');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username','password')) {
exit('Login Failed');
}
// outputs the contents of filename.remote to the screen
echo $sftp->get('filename.remote');
?>