Exceptions
5 days ago
apache.php
5 days ago
apcu.php
5 days ago
array.php
5 days ago
bzip2.php
5 days ago
calendar.php
5 days ago
classobj.php
5 days ago
com.php
5 days ago
cubrid.php
5 days ago
curl.php
5 days ago
datetime.php
5 days ago
dir.php
5 days ago
eio.php
5 days ago
errorfunc.php
5 days ago
exec.php
5 days ago
fileinfo.php
5 days ago
filesystem.php
5 days ago
filter.php
5 days ago
fpm.php
5 days ago
ftp.php
5 days ago
funchand.php
5 days ago
functionsList.php
5 days ago
gmp.php
5 days ago
gnupg.php
5 days ago
hash.php
5 days ago
ibase.php
5 days ago
ibmDb2.php
5 days ago
iconv.php
5 days ago
image.php
5 days ago
imap.php
5 days ago
info.php
5 days ago
ingres-ii.php
5 days ago
inotify.php
5 days ago
json.php
5 days ago
ldap.php
5 days ago
libxml.php
5 days ago
lzf.php
5 days ago
mailparse.php
5 days ago
mbstring.php
5 days ago
misc.php
5 days ago
msql.php
5 days ago
mysql.php
5 days ago
mysqli.php
5 days ago
mysqlndMs.php
5 days ago
mysqlndQc.php
5 days ago
network.php
5 days ago
oci8.php
5 days ago
opcache.php
5 days ago
openssl.php
5 days ago
outcontrol.php
5 days ago
password.php
5 days ago
pcntl.php
5 days ago
pcre.php
5 days ago
pdf.php
5 days ago
pgsql.php
5 days ago
posix.php
5 days ago
ps.php
5 days ago
pspell.php
5 days ago
readline.php
5 days ago
rpminfo.php
5 days ago
rrd.php
5 days ago
sem.php
5 days ago
session.php
5 days ago
shmop.php
5 days ago
simplexml.php
5 days ago
sockets.php
5 days ago
sodium.php
5 days ago
solr.php
5 days ago
spl.php
5 days ago
sqlsrv.php
5 days ago
ssdeep.php
5 days ago
ssh2.php
5 days ago
stream.php
5 days ago
strings.php
5 days ago
swoole.php
5 days ago
uodbc.php
5 days ago
uopz.php
5 days ago
url.php
5 days ago
var.php
5 days ago
xdiff.php
5 days ago
xml.php
5 days ago
xmlrpc.php
5 days ago
yaml.php
5 days ago
yaz.php
5 days ago
zip.php
5 days ago
zlib.php
5 days ago
ssh2.php
605 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\Ssh2Exception; |
| 6 | /** |
| 7 | * Authenticate over SSH using the ssh agent |
| 8 | * |
| 9 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 10 | * ssh2_connect. |
| 11 | * @param string $username Remote user name. |
| 12 | * @throws Ssh2Exception |
| 13 | * |
| 14 | */ |
| 15 | function ssh2_auth_agent($session, string $username): void |
| 16 | { |
| 17 | error_clear_last(); |
| 18 | $result = \ssh2_auth_agent($session, $username); |
| 19 | if ($result === \false) { |
| 20 | throw Ssh2Exception::createFromPhpError(); |
| 21 | } |
| 22 | } |
| 23 | /** |
| 24 | * Authenticate using a public hostkey read from a file. |
| 25 | * |
| 26 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 27 | * ssh2_connect. |
| 28 | * @param string $username |
| 29 | * @param string $hostname |
| 30 | * @param string $pubkeyfile |
| 31 | * @param string $privkeyfile |
| 32 | * @param string $passphrase If privkeyfile is encrypted (which it should |
| 33 | * be), the passphrase must be provided. |
| 34 | * @param string $local_username If local_username is omitted, then the value |
| 35 | * for username will be used for it. |
| 36 | * @throws Ssh2Exception |
| 37 | * |
| 38 | */ |
| 39 | function ssh2_auth_hostbased_file($session, string $username, string $hostname, string $pubkeyfile, string $privkeyfile, string $passphrase = null, string $local_username = null): void |
| 40 | { |
| 41 | error_clear_last(); |
| 42 | if ($local_username !== null) { |
| 43 | $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase, $local_username); |
| 44 | } elseif ($passphrase !== null) { |
| 45 | $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase); |
| 46 | } else { |
| 47 | $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile); |
| 48 | } |
| 49 | if ($result === \false) { |
| 50 | throw Ssh2Exception::createFromPhpError(); |
| 51 | } |
| 52 | } |
| 53 | /** |
| 54 | * Authenticate over SSH using a plain password. Since version 0.12 this function |
| 55 | * also supports keyboard_interactive method. |
| 56 | * |
| 57 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 58 | * ssh2_connect. |
| 59 | * @param string $username Remote user name. |
| 60 | * @param string $password Password for username |
| 61 | * @throws Ssh2Exception |
| 62 | * |
| 63 | */ |
| 64 | function ssh2_auth_password($session, string $username, string $password): void |
| 65 | { |
| 66 | error_clear_last(); |
| 67 | $result = \ssh2_auth_password($session, $username, $password); |
| 68 | if ($result === \false) { |
| 69 | throw Ssh2Exception::createFromPhpError(); |
| 70 | } |
| 71 | } |
| 72 | /** |
| 73 | * Authenticate using a public key read from a file. |
| 74 | * |
| 75 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 76 | * ssh2_connect. |
| 77 | * @param string $username |
| 78 | * @param string $pubkeyfile The public key file needs to be in OpenSSH's format. It should look something like: |
| 79 | * |
| 80 | * ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110 |
| 81 | * @param string $privkeyfile |
| 82 | * @param string $passphrase If privkeyfile is encrypted (which it should |
| 83 | * be), the passphrase must be provided. |
| 84 | * @throws Ssh2Exception |
| 85 | * |
| 86 | */ |
| 87 | function ssh2_auth_pubkey_file($session, string $username, string $pubkeyfile, string $privkeyfile, string $passphrase = null): void |
| 88 | { |
| 89 | error_clear_last(); |
| 90 | if ($passphrase !== null) { |
| 91 | $result = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile, $passphrase); |
| 92 | } else { |
| 93 | $result = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile); |
| 94 | } |
| 95 | if ($result === \false) { |
| 96 | throw Ssh2Exception::createFromPhpError(); |
| 97 | } |
| 98 | } |
| 99 | /** |
| 100 | * Establish a connection to a remote SSH server. |
| 101 | * |
| 102 | * Once connected, the client should verify the server's hostkey using |
| 103 | * ssh2_fingerprint, then authenticate using either |
| 104 | * password or public key. |
| 105 | * |
| 106 | * @param string $host |
| 107 | * @param int $port |
| 108 | * @param array $methods methods may be an associative array with up to four parameters |
| 109 | * as described below. |
| 110 | * |
| 111 | * |
| 112 | * methods may be an associative array |
| 113 | * with any or all of the following parameters. |
| 114 | * |
| 115 | * |
| 116 | * |
| 117 | * Index |
| 118 | * Meaning |
| 119 | * Supported Values* |
| 120 | * |
| 121 | * |
| 122 | * |
| 123 | * |
| 124 | * kex |
| 125 | * |
| 126 | * List of key exchange methods to advertise, comma separated |
| 127 | * in order of preference. |
| 128 | * |
| 129 | * |
| 130 | * diffie-hellman-group1-sha1, |
| 131 | * diffie-hellman-group14-sha1, and |
| 132 | * diffie-hellman-group-exchange-sha1 |
| 133 | * |
| 134 | * |
| 135 | * |
| 136 | * hostkey |
| 137 | * |
| 138 | * List of hostkey methods to advertise, comma separated |
| 139 | * in order of preference. |
| 140 | * |
| 141 | * |
| 142 | * ssh-rsa and |
| 143 | * ssh-dss |
| 144 | * |
| 145 | * |
| 146 | * |
| 147 | * client_to_server |
| 148 | * |
| 149 | * Associative array containing crypt, compression, and |
| 150 | * message authentication code (MAC) method preferences |
| 151 | * for messages sent from client to server. |
| 152 | * |
| 153 | * |
| 154 | * |
| 155 | * |
| 156 | * server_to_client |
| 157 | * |
| 158 | * Associative array containing crypt, compression, and |
| 159 | * message authentication code (MAC) method preferences |
| 160 | * for messages sent from server to client. |
| 161 | * |
| 162 | * |
| 163 | * |
| 164 | * |
| 165 | * |
| 166 | * |
| 167 | * |
| 168 | * * - Supported Values are dependent on methods supported by underlying library. |
| 169 | * See libssh2 documentation for additional |
| 170 | * information. |
| 171 | * |
| 172 | * |
| 173 | * |
| 174 | * client_to_server and |
| 175 | * server_to_client may be an associative array |
| 176 | * with any or all of the following parameters. |
| 177 | * |
| 178 | * |
| 179 | * |
| 180 | * |
| 181 | * Index |
| 182 | * Meaning |
| 183 | * Supported Values* |
| 184 | * |
| 185 | * |
| 186 | * |
| 187 | * |
| 188 | * crypt |
| 189 | * List of crypto methods to advertise, comma separated |
| 190 | * in order of preference. |
| 191 | * |
| 192 | * rijndael-cbc@lysator.liu.se, |
| 193 | * aes256-cbc, |
| 194 | * aes192-cbc, |
| 195 | * aes128-cbc, |
| 196 | * 3des-cbc, |
| 197 | * blowfish-cbc, |
| 198 | * cast128-cbc, |
| 199 | * arcfour, and |
| 200 | * none** |
| 201 | * |
| 202 | * |
| 203 | * |
| 204 | * comp |
| 205 | * List of compression methods to advertise, comma separated |
| 206 | * in order of preference. |
| 207 | * |
| 208 | * zlib and |
| 209 | * none |
| 210 | * |
| 211 | * |
| 212 | * |
| 213 | * mac |
| 214 | * List of MAC methods to advertise, comma separated |
| 215 | * in order of preference. |
| 216 | * |
| 217 | * hmac-sha1, |
| 218 | * hmac-sha1-96, |
| 219 | * hmac-ripemd160, |
| 220 | * hmac-ripemd160@openssh.com, and |
| 221 | * none** |
| 222 | * |
| 223 | * |
| 224 | * |
| 225 | * |
| 226 | * |
| 227 | * |
| 228 | * |
| 229 | * Crypt and MAC method "none" |
| 230 | * |
| 231 | * For security reasons, none is disabled by the underlying |
| 232 | * libssh2 library unless explicitly enabled |
| 233 | * during build time by using the appropriate ./configure options. See documentation |
| 234 | * for the underlying library for more information. |
| 235 | * |
| 236 | * |
| 237 | * |
| 238 | * For security reasons, none is disabled by the underlying |
| 239 | * libssh2 library unless explicitly enabled |
| 240 | * during build time by using the appropriate ./configure options. See documentation |
| 241 | * for the underlying library for more information. |
| 242 | * @param array $callbacks callbacks may be an associative array with any |
| 243 | * or all of the following parameters. |
| 244 | * |
| 245 | * |
| 246 | * Callbacks parameters |
| 247 | * |
| 248 | * |
| 249 | * |
| 250 | * |
| 251 | * Index |
| 252 | * Meaning |
| 253 | * Prototype |
| 254 | * |
| 255 | * |
| 256 | * |
| 257 | * |
| 258 | * ignore |
| 259 | * |
| 260 | * Name of function to call when an |
| 261 | * SSH2_MSG_IGNORE packet is received |
| 262 | * |
| 263 | * void ignore_cb($message) |
| 264 | * |
| 265 | * |
| 266 | * debug |
| 267 | * |
| 268 | * Name of function to call when an |
| 269 | * SSH2_MSG_DEBUG packet is received |
| 270 | * |
| 271 | * void debug_cb($message, $language, $always_display) |
| 272 | * |
| 273 | * |
| 274 | * macerror |
| 275 | * |
| 276 | * Name of function to call when a packet is received but the |
| 277 | * message authentication code failed. If the callback returns |
| 278 | * TRUE, the mismatch will be ignored, otherwise the connection |
| 279 | * will be terminated. |
| 280 | * |
| 281 | * bool macerror_cb($packet) |
| 282 | * |
| 283 | * |
| 284 | * disconnect |
| 285 | * |
| 286 | * Name of function to call when an |
| 287 | * SSH2_MSG_DISCONNECT packet is received |
| 288 | * |
| 289 | * void disconnect_cb($reason, $message, $language) |
| 290 | * |
| 291 | * |
| 292 | * |
| 293 | * |
| 294 | * @return resource Returns a resource on success. |
| 295 | * @throws Ssh2Exception |
| 296 | * |
| 297 | */ |
| 298 | function ssh2_connect(string $host, int $port = 22, array $methods = null, array $callbacks = null) |
| 299 | { |
| 300 | error_clear_last(); |
| 301 | if ($callbacks !== null) { |
| 302 | $result = \ssh2_connect($host, $port, $methods, $callbacks); |
| 303 | } elseif ($methods !== null) { |
| 304 | $result = \ssh2_connect($host, $port, $methods); |
| 305 | } else { |
| 306 | $result = \ssh2_connect($host, $port); |
| 307 | } |
| 308 | if ($result === \false) { |
| 309 | throw Ssh2Exception::createFromPhpError(); |
| 310 | } |
| 311 | return $result; |
| 312 | } |
| 313 | /** |
| 314 | * Close a connection to a remote SSH server. |
| 315 | * |
| 316 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 317 | * ssh2_connect. |
| 318 | * @throws Ssh2Exception |
| 319 | * |
| 320 | */ |
| 321 | function ssh2_disconnect($session): void |
| 322 | { |
| 323 | error_clear_last(); |
| 324 | $result = \ssh2_disconnect($session); |
| 325 | if ($result === \false) { |
| 326 | throw Ssh2Exception::createFromPhpError(); |
| 327 | } |
| 328 | } |
| 329 | /** |
| 330 | * Execute a command at the remote end and allocate a channel for it. |
| 331 | * |
| 332 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 333 | * ssh2_connect. |
| 334 | * @param string $command |
| 335 | * @param string $pty |
| 336 | * @param array $env env may be passed as an associative array of |
| 337 | * name/value pairs to set in the target environment. |
| 338 | * @param int $width Width of the virtual terminal. |
| 339 | * @param int $height Height of the virtual terminal. |
| 340 | * @param int $width_height_type width_height_type should be one of |
| 341 | * SSH2_TERM_UNIT_CHARS or |
| 342 | * SSH2_TERM_UNIT_PIXELS. |
| 343 | * @return resource Returns a stream on success. |
| 344 | * @throws Ssh2Exception |
| 345 | * |
| 346 | */ |
| 347 | function ssh2_exec($session, string $command, string $pty = null, array $env = null, int $width = 80, int $height = 25, int $width_height_type = \SSH2_TERM_UNIT_CHARS) |
| 348 | { |
| 349 | error_clear_last(); |
| 350 | if ($width_height_type !== \SSH2_TERM_UNIT_CHARS) { |
| 351 | $result = \ssh2_exec($session, $command, $pty, $env, $width, $height, $width_height_type); |
| 352 | } elseif ($height !== 25) { |
| 353 | $result = \ssh2_exec($session, $command, $pty, $env, $width, $height); |
| 354 | } elseif ($width !== 80) { |
| 355 | $result = \ssh2_exec($session, $command, $pty, $env, $width); |
| 356 | } elseif ($env !== null) { |
| 357 | $result = \ssh2_exec($session, $command, $pty, $env); |
| 358 | } elseif ($pty !== null) { |
| 359 | $result = \ssh2_exec($session, $command, $pty); |
| 360 | } else { |
| 361 | $result = \ssh2_exec($session, $command); |
| 362 | } |
| 363 | if ($result === \false) { |
| 364 | throw Ssh2Exception::createFromPhpError(); |
| 365 | } |
| 366 | return $result; |
| 367 | } |
| 368 | /** |
| 369 | * |
| 370 | * |
| 371 | * @param resource $pkey Publickey Subsystem resource created by ssh2_publickey_init. |
| 372 | * @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa |
| 373 | * @param string $blob Publickey blob as raw binary data |
| 374 | * @param bool $overwrite If the specified key already exists, should it be overwritten? |
| 375 | * @param array $attributes Associative array of attributes to assign to this public key. |
| 376 | * Refer to ietf-secsh-publickey-subsystem for a list of supported attributes. |
| 377 | * To mark an attribute as mandatory, precede its name with an asterisk. |
| 378 | * If the server is unable to support an attribute marked mandatory, |
| 379 | * it will abort the add process. |
| 380 | * @throws Ssh2Exception |
| 381 | * |
| 382 | */ |
| 383 | function ssh2_publickey_add($pkey, string $algoname, string $blob, bool $overwrite = \false, array $attributes = null): void |
| 384 | { |
| 385 | error_clear_last(); |
| 386 | if ($attributes !== null) { |
| 387 | $result = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite, $attributes); |
| 388 | } else { |
| 389 | $result = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite); |
| 390 | } |
| 391 | if ($result === \false) { |
| 392 | throw Ssh2Exception::createFromPhpError(); |
| 393 | } |
| 394 | } |
| 395 | /** |
| 396 | * Request the Publickey subsystem from an already connected SSH2 server. |
| 397 | * |
| 398 | * The publickey subsystem allows an already connected and authenticated |
| 399 | * client to manage the list of authorized public keys stored on the |
| 400 | * target server in an implementation agnostic manner. |
| 401 | * If the remote server does not support the publickey subsystem, |
| 402 | * the ssh2_publickey_init function will return FALSE. |
| 403 | * |
| 404 | * @param resource $session |
| 405 | * @return resource Returns an SSH2 Publickey Subsystem resource for use |
| 406 | * with all other ssh2_publickey_*() methods. |
| 407 | * @throws Ssh2Exception |
| 408 | * |
| 409 | */ |
| 410 | function ssh2_publickey_init($session) |
| 411 | { |
| 412 | error_clear_last(); |
| 413 | $result = \ssh2_publickey_init($session); |
| 414 | if ($result === \false) { |
| 415 | throw Ssh2Exception::createFromPhpError(); |
| 416 | } |
| 417 | return $result; |
| 418 | } |
| 419 | /** |
| 420 | * Removes an authorized publickey. |
| 421 | * |
| 422 | * @param resource $pkey Publickey Subsystem Resource |
| 423 | * @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa |
| 424 | * @param string $blob Publickey blob as raw binary data |
| 425 | * @throws Ssh2Exception |
| 426 | * |
| 427 | */ |
| 428 | function ssh2_publickey_remove($pkey, string $algoname, string $blob): void |
| 429 | { |
| 430 | error_clear_last(); |
| 431 | $result = \ssh2_publickey_remove($pkey, $algoname, $blob); |
| 432 | if ($result === \false) { |
| 433 | throw Ssh2Exception::createFromPhpError(); |
| 434 | } |
| 435 | } |
| 436 | /** |
| 437 | * Copy a file from the remote server to the local filesystem using the SCP protocol. |
| 438 | * |
| 439 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 440 | * ssh2_connect. |
| 441 | * @param string $remote_file Path to the remote file. |
| 442 | * @param string $local_file Path to the local file. |
| 443 | * @throws Ssh2Exception |
| 444 | * |
| 445 | */ |
| 446 | function ssh2_scp_recv($session, string $remote_file, string $local_file): void |
| 447 | { |
| 448 | error_clear_last(); |
| 449 | $result = \ssh2_scp_recv($session, $remote_file, $local_file); |
| 450 | if ($result === \false) { |
| 451 | throw Ssh2Exception::createFromPhpError(); |
| 452 | } |
| 453 | } |
| 454 | /** |
| 455 | * Copy a file from the local filesystem to the remote server using the SCP protocol. |
| 456 | * |
| 457 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 458 | * ssh2_connect. |
| 459 | * @param string $local_file Path to the local file. |
| 460 | * @param string $remote_file Path to the remote file. |
| 461 | * @param int $create_mode The file will be created with the mode specified by |
| 462 | * create_mode. |
| 463 | * @throws Ssh2Exception |
| 464 | * |
| 465 | */ |
| 466 | function ssh2_scp_send($session, string $local_file, string $remote_file, int $create_mode = 0644): void |
| 467 | { |
| 468 | error_clear_last(); |
| 469 | $result = \ssh2_scp_send($session, $local_file, $remote_file, $create_mode); |
| 470 | if ($result === \false) { |
| 471 | throw Ssh2Exception::createFromPhpError(); |
| 472 | } |
| 473 | } |
| 474 | /** |
| 475 | * Attempts to change the mode of the specified file to that given in |
| 476 | * mode. |
| 477 | * |
| 478 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 479 | * @param string $filename Path to the file. |
| 480 | * @param int $mode Permissions on the file. See the chmod for more details on this parameter. |
| 481 | * @throws Ssh2Exception |
| 482 | * |
| 483 | */ |
| 484 | function ssh2_sftp_chmod($sftp, string $filename, int $mode): void |
| 485 | { |
| 486 | error_clear_last(); |
| 487 | $result = \ssh2_sftp_chmod($sftp, $filename, $mode); |
| 488 | if ($result === \false) { |
| 489 | throw Ssh2Exception::createFromPhpError(); |
| 490 | } |
| 491 | } |
| 492 | /** |
| 493 | * Creates a directory on the remote file server with permissions set to |
| 494 | * mode. |
| 495 | * |
| 496 | * This function is similar to using mkdir with the |
| 497 | * ssh2.sftp:// wrapper. |
| 498 | * |
| 499 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 500 | * @param string $dirname Path of the new directory. |
| 501 | * @param int $mode Permissions on the new directory. |
| 502 | * @param bool $recursive If recursive is TRUE any parent directories |
| 503 | * required for dirname will be automatically created as well. |
| 504 | * @throws Ssh2Exception |
| 505 | * |
| 506 | */ |
| 507 | function ssh2_sftp_mkdir($sftp, string $dirname, int $mode = 0777, bool $recursive = \false): void |
| 508 | { |
| 509 | error_clear_last(); |
| 510 | $result = \ssh2_sftp_mkdir($sftp, $dirname, $mode, $recursive); |
| 511 | if ($result === \false) { |
| 512 | throw Ssh2Exception::createFromPhpError(); |
| 513 | } |
| 514 | } |
| 515 | /** |
| 516 | * Renames a file on the remote filesystem. |
| 517 | * |
| 518 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 519 | * @param string $from The current file that is being renamed. |
| 520 | * @param string $to The new file name that replaces from. |
| 521 | * @throws Ssh2Exception |
| 522 | * |
| 523 | */ |
| 524 | function ssh2_sftp_rename($sftp, string $from, string $to): void |
| 525 | { |
| 526 | error_clear_last(); |
| 527 | $result = \ssh2_sftp_rename($sftp, $from, $to); |
| 528 | if ($result === \false) { |
| 529 | throw Ssh2Exception::createFromPhpError(); |
| 530 | } |
| 531 | } |
| 532 | /** |
| 533 | * Removes a directory from the remote file server. |
| 534 | * |
| 535 | * This function is similar to using rmdir with the |
| 536 | * ssh2.sftp:// wrapper. |
| 537 | * |
| 538 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 539 | * @param string $dirname |
| 540 | * @throws Ssh2Exception |
| 541 | * |
| 542 | */ |
| 543 | function ssh2_sftp_rmdir($sftp, string $dirname): void |
| 544 | { |
| 545 | error_clear_last(); |
| 546 | $result = \ssh2_sftp_rmdir($sftp, $dirname); |
| 547 | if ($result === \false) { |
| 548 | throw Ssh2Exception::createFromPhpError(); |
| 549 | } |
| 550 | } |
| 551 | /** |
| 552 | * Creates a symbolic link named link on the remote |
| 553 | * filesystem pointing to target. |
| 554 | * |
| 555 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 556 | * @param string $target Target of the symbolic link. |
| 557 | * @param string $link |
| 558 | * @throws Ssh2Exception |
| 559 | * |
| 560 | */ |
| 561 | function ssh2_sftp_symlink($sftp, string $target, string $link): void |
| 562 | { |
| 563 | error_clear_last(); |
| 564 | $result = \ssh2_sftp_symlink($sftp, $target, $link); |
| 565 | if ($result === \false) { |
| 566 | throw Ssh2Exception::createFromPhpError(); |
| 567 | } |
| 568 | } |
| 569 | /** |
| 570 | * Deletes a file on the remote filesystem. |
| 571 | * |
| 572 | * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp. |
| 573 | * @param string $filename |
| 574 | * @throws Ssh2Exception |
| 575 | * |
| 576 | */ |
| 577 | function ssh2_sftp_unlink($sftp, string $filename): void |
| 578 | { |
| 579 | error_clear_last(); |
| 580 | $result = \ssh2_sftp_unlink($sftp, $filename); |
| 581 | if ($result === \false) { |
| 582 | throw Ssh2Exception::createFromPhpError(); |
| 583 | } |
| 584 | } |
| 585 | /** |
| 586 | * Request the SFTP subsystem from an already connected SSH2 server. |
| 587 | * |
| 588 | * @param resource $session An SSH connection link identifier, obtained from a call to |
| 589 | * ssh2_connect. |
| 590 | * @return resource This method returns an SSH2 SFTP resource for use with |
| 591 | * all other ssh2_sftp_*() methods and the |
| 592 | * ssh2.sftp:// fopen wrapper. |
| 593 | * @throws Ssh2Exception |
| 594 | * |
| 595 | */ |
| 596 | function ssh2_sftp($session) |
| 597 | { |
| 598 | error_clear_last(); |
| 599 | $result = \ssh2_sftp($session); |
| 600 | if ($result === \false) { |
| 601 | throw Ssh2Exception::createFromPhpError(); |
| 602 | } |
| 603 | return $result; |
| 604 | } |
| 605 |