在OS X系统中php访问sftp时需要ssh2扩展的安装
php -v

brew install homebrew/php/php55-ssh2

【实现方式】
<?php $connection = ssh2_connect('192.168.0.145', 22); ssh2_auth_password($connection, 'username', 'password'); $stream = ssh2_exec($connection, '/usr/local/bin/php -i'); stream_set_blocking( $stream, true ); echo (stream_get_contents($stream)); $stream = ssh2_exec($connection, 'ls'); stream_set_blocking( $stream, true ); echo (stream_get_contents($stream)); ?>

浙公网安备 33010602011771号