Re: Hoping for a working example of SFTP in PHP

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

 



David,

If you are script on a web server, I just noticed on the php manual, that the ssh2 wrappers are restricted by allow_url_fopen in php.ini. https://www.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options, so if this is off it won't work in the browser.  Often times hosts disable this in the apache or php-fpm php.ini files but allow it in the php-cli php.ini.  I have been running my test script from the command line.

Also make sure to pass the exact path to the wrapper.  pecl ssh2 differs from things like openssh where it drops you in your home directory.  So if public_html is at /home/user/public_html, connect with ssh2.sftp://6/home/user/public_html/test.txt.

Eric

On 2/3/21 8:14 AM, David Spector wrote:
Dear R. Eric Wheeler,

I just can't get the first approach to work (ssh2_connect, ssh2_auth_pubkey_file, ssh2_sftp, copy,

using either of these exact wrappers (6 is the ssh2_stfp resource):

ssh2.sftp://6/test.txt

or

ssh2.sftp://6/public_html/test.txt

With the test.txt file existing in both the document root and public_html directories on the remote computer, the file_exists function keeps returning false even though I added a call to clearstatcache. My PHP.ini file has wrappers enabled and the SSH2 extension is installed.

And the copy function is even worse: it times out in the browser.

The second approach works successfully (ssh2_connect, ssh2_scp_send).

If you can't help me with with the first approach, I'll drop it. But I would like to offer my readers both alternatives.

David



[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