ssh2:// - Secure Shell 2
ssh2:// - Secure Shell 2
설명
ssh2.shell:// ssh2.exec:// ssh2.tunnel:// ssh2.sftp:// ssh2.scp://(PECL)
기존 URI 로그인 세부 정보를 수락하는 것 외에도 ssh2 래퍼는 URL의 호스트 부분에 연결 리소스를 전달하여 열린 연결을 재사용합니다.
용법
- 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
옵션
Wrapper Summary
Attribute | ssh2.shell | ssh2.exec | ssh2.tunnel | ssh2.sftp | ssh2.scp |
---|---|---|---|---|---|
Restricted by allow_url_fopen | Yes | Yes | Yes | Yes | Yes |
Allows Reading | Yes | Yes | Yes | Yes | Yes |
Allows Writing | Yes | Yes | Yes | Yes | No |
Allows Appending | No | No | No | Yes (When supported by server) | No |
Allows Simultaneous Reading and Writing | Yes | Yes | Yes | Yes | No |
Supports stat() | No | No | No | Yes | No |
Supports unlink() | No | No | No | Yes | No |
Supports rename() | No | No | No | Yes | No |
Supports mkdir() | No | No | No | Yes | No |
Supports rmdir() | No | No | No | Yes | No |
Context options
Name | Usage | Default |
---|---|---|
session |
Preconnected ssh2 resource to be reused | |
sftp |
Preallocated sftp resource to be reused | |
methods |
Key exchange, hostkey, cipher, compression, and MAC methods to use | |
callbacks |
||
username |
Username to connect as | |
password |
Password to use with password authentication | |
pubkey_file |
Name of public key file to use for authentication | |
privkey_file |
Name of private key file to use for authentication | |
env |
Associate array of environment variables to set | |
term |
Terminal emulation type to request when allocating a pty | |
term_width |
Width of terminal requested when allocating a pty | |
term_height |
Height of terminal requested when allocating a pty | |
term_units |
Units to use with term_width and term_height | SSH2_TERM_UNIT_CHARS |
Examples
예제 #1 활성 연결에서 스트림 열기
<?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');
?>
예제 #2 이 $session 변수를 계속 사용할 수 있어야 합니다!
ssh2.*://$session 래퍼를 사용하려면 $session 리소스 변수를 유지해야 합니다. 아래 코드에는 원하는 효과가 없습니다.
<?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');
$connection_string = "ssh2.sftp://$session/";
unset($session);
$stream = fopen($connection_string . "path/to/file", 'r');
?>
unset()은 $connection_string이 $session 변수에 대한 참조를 보유하지 않고 이 변수에서 파생된 문자열 캐스트를 보유하기 때문에 세션을 닫습니다. 이것은 (함수에서와 같이) 범위를 벗어나기 때문에 unset()이 암시적일 때도 발생합니다.