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 的一部分的連線資源。

例子 M-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');
?>

表格 M-8. 封裝協定摘要

屬性ssh2.shellssh2.execssh2.tunnelssh2.sftpssh2.scp
受限於 allow_url_fopen
容許讀取
容許寫入
容許附加是 (若伺服器支援)
容許同時讀寫
支援 stat()
支援 unlink()
支援 rename()
支援 mkdir()
支援 rmdir()

表格 M-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