phizzl / php-ssh2-client
此包已被废弃,不再维护。没有推荐替代包。
用于通过SSH2传输文件的库
v1.0.0
2017-09-28 21:37 UTC
Requires
- ext-ssh2: *
- monolog/monolog: ^1.23
This package is auto-updated.
Last update: 2023-03-12 23:45:13 UTC
README
用PHP编写的SSH2客户端
认证
您可以选择公钥、密码和无认证三种认证模式。
使用密码进行认证
$auth = new PasswordAuthentication("vagrant", "vagrant");
使用公钥和私钥对进行认证
$auth = new PublicKeyAuthentication("vagrant", "/path/to/id_rsa.pub", "/path/to/id_rsa", "keypassword");
无认证
$auth = new NoneAuthentication("vagrant");
创建SSH2会话
配置好认证后,您可以创建SSH2会话并将认证传递给它。
$auth = new PasswordAuthentication("vagrant", "vagrant"); $session = new SshSession("localhost", 22, $auth);
创建SSH2客户端
现在您已经有一个会话,可以创建SSH2客户端并将会话传递给它。
$auth = new PasswordAuthentication("vagrant", "vagrant"); $session = new SshSession("localhost", 22, $auth); $sshClient = new SshClient($session);
使用SSH2客户端
创建SSH2客户端后,您就可以开始使用了。
$sshClient->sendFile('/local/path/to/file.txt, '~/uploads/file.txt');
$sshClient->receiveFile('~/downloads/remote.file', '/local/path/local.file');
$sshClient->removeFile('~/downloads/remote.file');
$sshClient->createDirectory('~/uploads/newdir');
$sshClient->removeDirectory('~/uploads/newdir', true)
$sshClient->sendDirectory('/local/dir', '~/uploads/newdir');
$sshClient->removeDirectory('~/uploads/newdir', true);
$sshClient->receiveDirectory('~/downloads/backup', '/local/dir/backup');