[英]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.