简体   繁体   English

php: @fopen 在 localhost 中工作,但在实时服务器中无效

[英]php: @fopen works in localhost but not in live server

I'm trying to get a remote file like this:我正在尝试获取这样的远程文件:

$host = 'sftp.hostname.com';
$username = 'user';
$password = '*****';
$port = '22';
$remote_file = 'TOB-20180919.text';
$connection = @ssh2_connect($host, $port);
if ($connection != false) {
    $login = @ssh2_auth_password($connection, $username, $password);
    if ((bool) $login) {
        $sftp = @ssh2_sftp($connection);
        if ($sftp != false) {
            $stream = @fopen("ssh2.sftp://$sftp" . "/" . "$remote_file", 'w');
            var_dump($stream);exit;
        }
    }
}

$stream prints false in my live server and true in my localhost. $stream打印false在我的直播服务器和true在我的本地主机。 What should I do now?我现在该怎么办?

I had face same issue so I was solve that type of issue using following code.please use this and check.我遇到了同样的问题,所以我使用以下代码解决了这种类型的问题。请使用它并检查。

put

$stream = @fopen("ssh2.sftp://".(int)$sftp."/".$remote_file, 'w');

instead of代替

$stream = @fopen("ssh2.sftp://$sftp" . "/" . "$remote_file", 'w');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP fopen错误在实时服务器上运行,但在测试服务器上失败 - PHP fopen error-works on live server but fails on test server PHP套接字服务器在本地主机上工作,但在实时服务器上不工作 - php socket server works on localhost but not on live server php套接字服务器仅在localhost上有效,而在实时服务器上不可用 - php socket server works only on localhost but not live server 使用Wordpress的PHP文件下载可在localhost上运行,但不能在实时服务器上运行 - PHP file download with Wordpress works on localhost but not live server PHP Cookies 在本地主机上运行良好,但在实时服务器上不起作用 - PHP Cookies works well on localhost, but it's not working on live server PHP - file_get_contents() 在 localhost 但在实时服务器上完美运行 - PHP - file_get_contents() works perfectly on localhost but on live server php 代码在 xampp 本地主机上运行良好,但在实时服务器上运行不正常 - php code works fine on xampp localhost but not working on live server 路由在localhost上有效,但在实时服务器上无效 - Routing works on localhost, but not on live server phpmailer可在localhost上运行,但不能在实时服务器上运行 - phpmailer works on localhost but not on live server 在我的本地主机(PHP 5.3.4)上运行的代码在实时服务器(PHP 5.2.17)上的旧PHP环境下不起作用 - Code that works on my localhost (PHP 5.3.4) is not working on older PHP environment on live server (PHP 5.2.17)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM