1.安装ssh扩展,在扩展链接下载对应版本的扩展放到php/ext/下,然后更改php.ini,输出phpinfo(),能看到就表示成功了
2.控制器代码(框架用的CI)
sftp类代码:
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/8/22
* Time: 16:00
*/
class Sftp
{
private $connection;
private $sftp;
public function __construct($params)
{
$host = $params['host'];//地址
$port = $params['port'];//端口
$this->connection = ssh2_connect($host,$port);
if (! $this->connection) throw new Exception