Secure Shell 2

ssh2.shell:// ssh2.exec:// ssh2.tunnel:// ssh2.sftp:// ssh2.scp:// PHP 4.3.0 及以上版本 (PECL)

  • ssh2.shell://user:pass@example.com:22/xterm

  • ssh2.exec://user:pass@example.com:22/usr/local/bin/somecmd

  • ssh2.tunnel://user:pass@example.com:22/192.168.0.1:14

  • ssh2.sftp://user:pass@example.com:22/path/to/filename

该封装器默认没有启用: 要使用 ssh2.*:// 封装器,必须安装 SSH2 扩展。可以到 PECL 下载。

除了接受传统 URI 的登录信息外,ssh2 封装器也重用主机 URL 的一部分的连接资源。

例子 L-2. 为活动连接打开流

<?php
$session
= ssh2_connect('example.com', 22);
ssh2_auth_pubkey_file($session, 'username', '/home/username/.ssh/id_rsa.pub',
                                            
'/home/username/.ssh/id_rsa', 'secret');
$stream = fopen("ssh2.tunnel://$session/remote.example.com:1234", 'r');
?>

表格 L-8. 封装协议摘要

属性ssh2.shellssh2.execssh2.tunnelssh2.sftpssh2.scp
受限于 allow_url_fopen
允许读取
允许写入
允许附加是 (若服务器支持)
允许同时读写
支持 stat()
支持 unlink()
支持 rename()
支持 mkdir()
支持 rmdir()

表格 L-9. 上下文选项

名称用法默认
session可重用预连接的 ssh2 连接资源 
sftp可重用预分配的 sftp 连接资源 
methods要使用的 Key exchange, hostkey, cipher, compression, 和 MAC 方法 
callbacks  
username连接的用户名 
password密码认证时需要的密码 
pubkey_file认证需要的 public key 文件名 
privkey_file认证需要的 private key 文件名 
env要设置的环境变量的数组 
term当分配一个控制台时使用的终端类型 
term_width当分配一个控制台时终端的宽度 
term_height当分配一个控制台时终端的高度 
term_units与 term_width 和 term_height 一同使用的单元SSH2_TERM_UNIT_CHARS


add a note add a note User Contributed Notes
There are no user contributed notes for this page.