PHP SDK,用于通过ssh、sftp等方式连接服务器。
2.1
2022-07-24 17:59 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: @stable
README
A PHP SDK for connect to servers via ssh, sftp an more.
依赖关系
- PHP >= 7.4
设置
如果您已经有文件,只需将以下依赖项添加到您的项目中:composer.json
"require": { "edvnetwork/php-ssh": "^2.1" }
将依赖项添加后,只需运行:composer.json
composer install
或者,您可以直接在终端运行
composer require edvnetwork/php-ssh
使用简单用户名和密码认证的SSH连接
<?php use EDV\net\ssh\SSHConnection; use EDV\net\ssh\auth\SSHPasswordAuthentication; $ssh = new SSHConnection(); $ssh->open('127.0.0.1'); $ssh->authenticate( new SSHPasswordAuthentication('user', 'password')); $directoryIterator = $ssh->getDirectoryIterator('/temp'); while ($directoryIterator->valid()) { $splFileInfo = $directoryIterator->current(); if ($splFileInfo->isFile()) { $splFileObject = $directoryIterator->openFile('r'); } $directoryIterator->next(); }
使用用户公钥的SSH连接
<?php use EDV\net\ssh\SSHConnection; use EDV\net\ssh\auth\SSHPublicKeyAuthentication; $ssh = new SSHConnection(); $ssh->open('example.com'); $ssh->authenticate(new SSHPublicKeyAuthentication('user', '/home/user/.ssh/id_rsa.pub', '/home/user/.ssh/id_rsa', 'passphrase')); $directoryIterator = $ssh->getDirectoryIterator('/temp'); while ($directoryIterator->valid()) { $splFileInfo = $directoryIterator->current(); if ($splFileInfo->isFile()) { $splFileObject = $directoryIterator->openFile('r'); } $directoryIterator->next(); }