Subject: Re: Request for help for beginner, thanks!

Re: Request for help for beginner, thanks!

From: Peter Stuge <>
Date: Mon, 18 Jan 2021 19:49:55 +0000


David Spector wrote:
> You may complain that ssh2 is an obscure area of PHP

Please be aware that the community on this mailing list is the author
of the libssh2 library which is written in the C programming language,
documented okay-to-well using the method common for unix-y C libraries
(man pages) and is intended for use by other C programs.

libssh2 (this our project here) includes various examples, also written
in C, some demonstrate a few SFTP uses, including upload, and other
demonstrate the different authentication methods.

libssh2 does support all authentication methods of the SSH v2 protocol.

To learn more about the SSH protocol architecture I can really
recommend looking at RFC 4251 which is quite readable:

SFTP is a so-called subsystem within the SSH architecture.

(This is not to be confused with the traditional FTP protocol secured
with SSL or TLS.)

As far as I know, the ssh2 PHP extension is not developed by anyone
in this community/on this mailing list.

It is however true that libssh2 was initially created to serve as the
foundation for the PHP ssh2 extension.

I honestly don't know who (if anyone?) maintains the PHP ssh2 extension.

If I've understood history correctly then the PHP ssh2 extension was
created by a single party primarily for their internal use, which could
explain why it would have terse documentation.

The cURL project was mentioned - that's actually also primarily a C library
named libcurl, although it happens to come with a very handy command line
utility to exercise the library.

The PHP curl extension uses libcurl directly.

libcurl supports, among other protocols, SFTP.

libcurl happens to use libssh2 to realise SFTP file transfers. :)
Also, the primary maintainer of libcurl is currently also head of libssh2.

libcurl is quite popular and can be simpler to use than libssh2 in C,
especially for SFTP, so the recommendation to use libcurl makes a lot of
sense for a C program.

Taking a quick look at the PHP ssh2 SFTP support it looks like that's
less important in PHP.

There is a very simple example of uploading a file using SFTP in PHP
through the ssh2 extension here:

Following the example, the first user comment includes a class wrapper.

This comment further down shows what is needed for publickey authentication
(by extending the wrapper class, but you can obviously just substitute
ssh2_auth_password() for ssh2_auth_pubkey_file() yourself in the example):

You'll obviously have to change 'r' to 'w' in the fopen call to write files
to your SFTP server instead of read.

> (example: the words "key" and "password" actually can apply to two or
> more different parameters of the sFTP protocol; the documentation uses
> them ambiguously).

Hm - which two different parameters do you mean? Maybe there is some
confusion here.

If you have improvements for the PHP ssh2 extension documentation I'm sure
that the PHP project will be happy to accept them, as we are if you want to
contribute improvements to the libssh2 C library documentation.

Hope this helps

Received on 2021-01-18