Hoping for a working example of SFTP in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a question about uploading a file (text.txt) securely in PHP using the SFTP protocol and a public/private key pair.

I have posted this question is several fora, but no one seems to know for sure how to do it. Although I've received much advice, none of the actual published examples (including those in the PHP Manual) are known to work, and do not work for me. I know my parameters are okay, since they work in CoreFTP and PuTTY, two manual applications that implement SFTP with private keys. Also, the short FTP insecure example in the PHP Manual works perfectly for me. There seem to be many subtle undocumented issues with getting any of the published example code using private keys to work. I'm inexperienced with SFTP and other advanced features of PHP and am hoping to find a working example.

So far I have tried a number of examples using the ssh2 PHP extension and the cURL PHP extension. They fail, and the error messages, if any, are uninformative.

A little background:

I do website development work for two small companies on a Windows computer (Apache/PHP 7), uploading to a remote production server (VPS/cPanel/Centos). My local software versions are: Windows 10 Hone/2004, Bitnami WAMP/7.4.13-0, Apache/2.4.46 (Win64), OpenSSL/1.1.1h, PHP/7.4.13, libssh2/1.9.0.

Where I am now is that I used cPanel on the remote server to install an SSH/SFTP public key for a particular account. I then copied the generated encrypted x.key and x.ppk private key files to my local computer. Now I am ready to upload files securely, if only PHP made the task easy. Unfortunately, it does not.

I know that phpseclib is available and is said to work well, but it is a very large PHP source code library, so I'd rather use the php_ssh2.dll or cURL PHP extension, or something similar.

In summary, I'm looking for someone who has successfully used SFTP file upload with private key in PHP to share their code with me. I pledge to test the code and post it further to help others with this difficult but increasingly important and useful problem.

David Spector
Springtime Software



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux