PHP 8.3.4 Released!

ssh2://

ssh2://Güvenli Kabuk 2

Açıklama

ssh2.shell:// ssh2.exec:// ssh2.tunnel:// ssh2.sftp:// ssh2.scp:// (PECL)

Bilginize: Bu sarmalayıcı öntanımlı olarak etkin değildir
ssh2.*:// sarmalayıcısını kullanmak için, » PECL'de bulunan » SSH2 eklentisinin kurulması gerekir.

Geleneksel URI oturum açma ayrıntılarını kabul etmenin yanı sıra, ssh2 sarmalayıcıları, URL'nin konak bölümündeki bağlantı kaynağını aktararak açık bağlantıları yeniden kullanır.

Kullanımı

  • 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

Seçenekler

Sarmalayıcı Özeti
Özellik ssh2.shell ssh2.exec ssh2.tunnel ssh2.sftp ssh2.scp
allow_url_fopen ile sınırlı Evet Evet Evet Evet Evet
Okuma izni Evet Evet Evet Evet Evet
Yazma izni Evet Evet Evet Evet Hayır
Ekleme izni Hayır Hayır Hayır Yes (Sunucu desteklerse) Hayır
Aynı anda okuma ve yazma Evet Evet Evet Evet Hayır
stat() desteği Hayır Hayır Hayır Evet Hayır
unlink() desteği Hayır Hayır Hayır Evet Hayır
rename() desteği Hayır Hayır Hayır Evet Hayır
mkdir() desteği Hayır Hayır Hayır Evet Hayır
rmdir() desteği Hayır Hayır Hayır Evet Hayır

Bağlam Seçenekleri
İsim Kullanım Öntanımlı
session Yeniden kullanılacak önceden bağlanmış ssh2 kaynağı  
sftp Yeniden kullanılacak önceden tahsis edilmiş sftp kaynağı  
methods Anahtar değişimi, ana anahtar, şifre, sıkıştırma ve kullanılacak MAC yöntemleri  
callbacks    
username Bağlantı için kullanıcı adı  
password Kimlik kanıtlama için parola  
pubkey_file Kimlik kanıtlamada kullanılacak genel anahtar dosyasının ismi  
privkey_file Kimlik kanıtlamada kullanılacak özel anahtar dosyasının ismi  
env Atanacak ortam değişkenlerinin ilişkisel dizisi  
term Bir pty tahsis ederken talep edilecek terminal türü  
term_width Bir pty tahsis ederken talep edilecek terminal genişliği  
term_height Bir pty tahsis ederken talep edilecek terminal yüksekliği  
term_units term_width ve term_height ile kullanılacak birimler SSH2_TERM_UNIT_CHARS

Örnekler

Örnek 1 - Etkin bir bağlantıda bir akım açmak

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

Örnek 2 - Bu $session değişkeni hazır tutulmalıdır!

ssh2.*://$session sarmalayıcılarını kullanmak için $session özkaynak değişkeni korunmalıdır. Aşağıdaki kod istenen etkiyi sağlamayacaktır:

<?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() oturumu kapatır, çünkü $connection_string $session değişkenine bir gönderim tutmaz, sadece ondan türetilmiş bir dizge ataması içerir. unset() örtük olduğunda da etki alanından çıktığından dolayı (bir işlevdeki gibi) bu olur.

add a note

User Contributed Notes 4 notes

up
7
exptom
10 years ago
The "password" context option can also be used to provide the passphrase for the keyfile supplied by "privkey_file" and "pubkey_file".

Note this bug: https://bugs.php.net/bug.php?id=58573
Encrypted keys may not work unless you build libssh2 against openssl. (It only worked for me on Debian Wheezy once I recompiled the library).
up
6
bluej100 at gmail dot com
10 years ago
Be aware that opendir is currently broken on sftp root directories, but you can work around it by appending a dot. See https://bugs.php.net/bug.php?id=64169 and http://stackoverflow.com/a/16238476/69173.
up
4
guilhem at no dot spam dot answeb dot net
6 years ago
Please beware of a PHP bug, noted by thomas at gielfeldt dot dk, that you must intval() the connection variable before putting it in the connection string :

<?php
$connection
= ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);
// See: https://bugs.php.net/bug.php?id=73597
$stream = fopen("ssh2.sftp://" . intval($sftp) . "/path/to/file", 'r');
?>
up
-1
thomas at gielfeldt dot dk
6 years ago
<?php
// Connect with public key.
$session = ssh2_connect('example.com', 22);
$result = ssh2_auth_pubkey_file($session, 'remote-username', '/home/local-username/.ssh/id_rsa.pub',
'/home/local-username/.ssh/id_rsa',
'secret');
// Setup sftp stream wrapper
$sftp = ssh2_sftp($session);
// See: https://bugs.php.net/bug.php?id=73597
$connection_string = 'ssh2.sftp://' . intval($sftp);

// List files in remote homedir.
$i = new \RecursiveDirectoryIterator("$connection_string/home/remote-username");
$r = new \RecursiveIteratorIterator($i);
foreach (
$r as $f) {
print
$f->getPathname() . "\n";
}
?>
To Top