You are on page 1of 6

PHP: ssh2:// - Manual

http://php.net/manual/es/wrappers.ssh2.php

Downloads
Documentation
Get Involved
Help

Search
Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Errors
Exceptions
Generators
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Context options and parameters
Supported Protocols and Wrappers
Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Session Security
Filesystem Security
Database Security
Error Reporting
Using Register Globals
User Submitted Data
Magic Quotes
Hiding PHP
Keeping Current
Features

1 de 6

28/01/17 00:45

PHP: ssh2:// - Manual

http://php.net/manual/es/wrappers.ssh2.php

HTTP authentication with PHP


Cookies
Sessions
Dealing with XForms
Handling file uploads
Using remote files
Connection handling
Persistent Database Connections
Safe Mode
Command line usage
Garbage Collection
DTrace Dynamic Tracing
Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Credit Card Processing
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
j
Next menu item
k
Previous menu item
gp
Previous man page
2 de 6

28/01/17 00:45

PHP: ssh2:// - Manual

http://php.net/manual/es/wrappers.ssh2.php

gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box
rar://
phar://
Manual de PHP
Referencia del lenguaje
Protocolos y Envolturas soportados
Change language: Spanish
Edit Report a Bug

ssh2://
ssh2:// Secure Shell 2

Descripcin
ssh2.shell:// ssh2.exec:// ssh2.tunnel:// ssh2.sftp:// ssh2.scp:// PHP 4.3.0 y
superior (PECL)
Nota: Esta envoltura no est habilitada por omisin
Para poder usarse la envoltura ssh2.*:// debe instalarase la
extensin SSH2 disponible en PECL.
Adems de permitir hacer un login tradicional en la URI, la envoltura ssh2
tambin puede reutilizar las conexiones ya abiertas, proporcionando el
recurso de conexin en el apartado host de la URL.

Uso
ssh2.shell://usuario:contrasea@ejemplo.com:22/xterm
ssh2.exec://usuario:contrasea@ejemplo.com:22/usr/local/bin/comando
ssh2.tunnel://usuario:contrasea@ejemplo.com:22/192.168.0.1:14
ssh2.sftp://usuario:contrasea@ejemplo.com:22/ruta/a/fichero

3 de 6

28/01/17 00:45

PHP: ssh2:// - Manual

http://php.net/manual/es/wrappers.ssh2.php

Opciones
Resumen de la Envoltura
ssh2.shell ssh2.exec ssh2.tunnel ssh2.sftp ssh2.scp

Atributo
Restringido por
S
allow_url_fopen
Permite Lecturas S
Permite
S
Escrituras
Permite Aadir
contenidos
Permite Lecturas
y Escrituras
Simultneas
Permite usar la
funcin stat()
Permite usar la
funcin unlink()
Permite usar la
funcin rename()
Permite usar la
funcin mkdir()
Permite usar la
funcin rmdir()

No

No

No

No

No

S (cuando
est
soportado
por el
servidor)

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

No

Opciones de contexto
Nombre
session
sftp
methods

Uso

Valor por
omisin

Recurso ssh2 preconectado a utilizar


Recurso sftp preubicado a reutilizar
mtodos a usar de entre Key exchange,
hostkey, cipher, compression, y MAC

callbacks
username

Nombre de usuario con el que conectar


Contrasea a utilizar en autenticacin con
password
contrasea
Nombre del fichero con la clave pblica que
pubkey_file
se usar para autenticar
Nombre del fichero con la clave privada que
privkey_file
se usar para autenticar
Array asociativo con las variables de entorno
env
que se van a asignar

4 de 6

28/01/17 00:45

PHP: ssh2:// - Manual

Nombre

http://php.net/manual/es/wrappers.ssh2.php

Valor por
omisin

Uso

Tipo de emulacin del terminal a solicitar


cuando se asigne un pty (pseudo terminal)
Ancho del terminal solicitado cuando se
term_width
asigne un pty
Altura del terminal solicitado cuando se
term_height
asigne un pty
Unidades a usar con term_width y con
term_units
term_height
term

SSH2_TERM_UNIT_CHARS

Ejemplos
Ejemplo #1 Abriendo un flujo a partir de una conexin activa
<?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');
?>

Ejemplo #2 La variable $session debe permanecer disponible!


Para utilizar la envoltura ssh2.*://$session debe mantenerse el recurso
$session disponible. El cdigo siguiente no tendr el efecto deseado:
<?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() cierra la sesin, ya que $connection_string no contiene una


referencia a la variable $session, simplemente una representacin de la
cadena derivada de ella. Esto tambin ocurre cuando unset() va implcito
porque se sale del mbito (como dentro de una funcin).
add a note

User Contributed Notes 2 notes


up
down
4
bluej100 at gmail dot com
3 years ago
5 de 6

28/01/17 00:45

PHP: ssh2:// - Manual

http://php.net/manual/es/wrappers.ssh2.php

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
down
1
exptom
3 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).

add a note

Protocolos y Envolturas soportados


file://
http://
ftp://
php://
zlib://
data://
glob://
phar://
ssh2://
rar://
ogg://
expect://
Copyright 2001-2017 The PHP Group
My PHP.net
Contact
Other PHP.net sites
Mirror sites
Privacy policy

6 de 6

28/01/17 00:45

You might also like