Subject: Request for help for beginner, thanks!

Request for help for beginner, thanks!

From: David Spector <>
Date: Sun, 17 Jan 2021 08:27:27 -0500

Dear libssh2 group,

This is the 2nd time I'm posting this. The last attempt didn't get
through and isn't in the Archive.

Please, I need the simplest possible PHP coding example of using libssh
or libssh2 to upload a single file using the sftp protocol in the
following environment: Windows, PHP running via a local server URL in a
browser (for example, the URL might be "localhost/upload.php"). My
actual application is considerably more complex, but this simple example
is all I need to get started.

I have downloaded zip file php_ssh2-1.2-7.4-ts-vc15-x64, and it contains
php_ssh2.dll, which I assume goes into the PHP/ext directory/folder. I'm
not aware of any other installation required.

I've been trying to understand this library for several weeks
(part-time), including trying to read, and just
been frustrated. I'm a beginner when it comes to cryptography.

So I am looking for SIMPLE instructions and a single example of simple
PHP code to upload a file using sftp.

It should look something like the following working insecure example,
but include a local encrypted (preferred) or unencrypted private key
pathnanme. It may optionally include the certificate pathname, if that
is required. It should not prompt the user for any information, just
upload the file silently like the following working code does insecurely:


echo "Uploading...".<br>;

if ($ftp===false)
     exit("Cannot connect to remote server (host)");

if (!$R)
     exit("Cannot login to remote server (host)");

if (!$R)
     exit("Cannot copy file '$file' to '$remoteDir$file' on remote server");


echo "...successfully done".<br>;

function GetConfigArr($file)
     global $pagesDir;
     if ($configStr===false)
         exit("*** Config file '$file' is missing from $pagesDir)";
     return json_decode($configStr,true);
     } // GetConfigArr

David Spector
PHP developer
Springtime Software
Maine, USA
Received on 2021-01-17