php - php:@fopen 在 localhost 中有效,但在实时服务器中无效
问题描述
我正在尝试获取这样的远程文件:
$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
false
在我的实时服务器和本地主机中打印true
。我现在该怎么办?
解决方案
我遇到了同样的问题,所以我使用以下代码解决了这类问题。请使用它并检查。
放
$stream = @fopen("ssh2.sftp://".(int)$sftp."/".$remote_file, 'w');
代替
$stream = @fopen("ssh2.sftp://$sftp" . "/" . "$remote_file", 'w');
推荐阅读
- php - Laravel 显示来自 foreach 的对象
- python - 使用 NamedAgg 聚合带有条件的 Pandas DataFrame
- c# - LINQ to Objects - 减少重复 - 在 select 语句中映射
- aws-sam - AWS SAM - 配置 TOML 文件
- c# - 如何找到发送http请求的时间C#
- php - 如果 PHP 中的值为空,如何取消设置数组
- r - 计算R中多个坐标的距离
- javascript - 按钮 onClick 不能与此 JS 一起使用或以编程方式触发 jquery Resizable Font-size?
- c# - CSVHelper 指数用逗号代替点
- javascript - Electron vue 应用程序 - 使用私有 repo 更新应用程序