stream_context_set_params不适用于ssh2.sftp包装器 [英] stream_context_set_params not works with ssh2.sftp wrapper

查看:113
本文介绍了stream_context_set_params不适用于ssh2.sftp包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用此处之类的功能.请检查下面的代码

I want to use functionality like here. Please check the code bellow

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);

我希望我的notify函数将至少被调用一次. 实际上,相同的代码适用于ftp包装器

I expect that my notify function will be called at least once. Actually, 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);

工作正常! notify函数被多次调用. 我尝试像这样使用sftp包装器

And it works fine! The notify function is called many times. I try to use sftp wrapper like this

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

它也不起作用. 有什么想法吗?

And it isn`t works too. Any ideas?

推荐答案

ssh2扩展名不支持通知回调.我不知道这是设计使然还是未实现,但是扩展代码缺少对以下函数的调用:

The ssh2 extension doesn't support notfication callbacks. I don't know if this is by design or just not implemented, but the extensions code is missing calls to functions like:

来自(PHP-5.4.10)/ext/standard/ftp_fopen_wrapper.c,第573行:

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

php_stream_notify_progress_init(context, 0, file_size);

一种解决方法,我尚未测试过,可能是使用ftps://(基于SSL的FTP).它应该符合您的安全需求,并且-如代码所示-将支持ftp等通知.详细地说,它使用与ftp相同的urlwrapper.

A workaround, which I've not tested yet might be to use ftps:// (FTP over ssl). It should fit your security needs and - as the code looks like - will support notifications as ftp. In detail, it uses the same urlwrapper as ftp.

这篇关于stream_context_set_params不适用于ssh2.sftp包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆