Re: Hoping for a working example of SFTP in PHP

[email protected] ("R. Eric Wheeler")
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.