Stream_context_set_params does not work with ssh2.sftp wrapper

I want to use features like here . Please check the code below.

function notify ( $notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max ) { echo "Runned \n"; }; $ctx = stream_context_create(); stream_set_params($ctx, array('notification' => 'notify')); $ssh_connection = ssh2_connect('myhost'); ssh2_auth_password($ssh_connection, 'login','pass'); $sftp_resource = ssh2_sftp($ssh_connection); $data = file_get_contents("ssh2.sftp://{$sftp_resource}/path/to/big/file", false, $ctx); 

I expect my notification function to be called at least once. In fact, the same code works for ftp wrappers

 function notify ( $notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max ) { echo "Runned \n"; }; $ctx = stream_context_create(); stream_set_params($ctx, array('notification' => 'notify')); $scheme = 'ftp'; $data = file_get_contents("{scheme}://username: password@host :port/path/to/file", false, $ctx); 

And everything works fine! The notification function is called many times. I am trying to use sftp wrapper like this

 $data = file_get_contents("ssh2.sftp://username: password@host :port/path/to/big/file", false, $ctx); 

And that doesn't work either. Any ideas?

+2
source share
2 answers

The ssh2 extension does not support notfication callbacks. I don’t know whether this is by design or simply not implemented, but the extension code does not contain calls to functions such as:

From (PHP-5.4.10) /ext/standard/ftp_fopen_wrapper.c, line 573:

 php_stream_notify_progress_init(context, 0, file_size); 

A workaround that I have not tested yet might be to use ftps:// (FTP via ssl). It should meet your security requirements and, as the code looks, will support notifications like ftp. In detail, it uses the same urlwrapper as ftp.

+2
source
+1
source

All Articles