我们改变了托管公司,而 ssh2 在哪里工作,它不再工作。我们已经ssh2
在新服务器上allow_url_fopen
启用了。
我能看到的唯一区别是旧服务器使用PHP 5.4.45
和新服务器使用PHP 5.6.28
.
但是,我现在收到以下错误。
Could not open remote file: ssh2.sftp://Resource id #337/my/directory/file.txt
这是我的代码示例:
$remote_host = "myhostinfohere";
$remote_port = 22;
$remote_user = "myuser";
$remote_pass = "mypassword";
$remote_dir = "/my/directory/";
$remote_file = 'file.txt';
try {
$remote_conn = ssh2_connect($remote_host, $remote_port);
} catch (Exception $e) {
die("could not connect to ".$remote_host);
}
try {
ssh2_auth_password($remote_conn, $remote_user, $remote_pass);
} catch (Exception $e) {
die("Password failed on ".$remote_host);
}
$sftp = ssh2_sftp($remote_conn);
$fetch_string = "ssh2.sftp://$sftp" . $remote_dir . $remote_file;
//If I add this it says it doesn't exists for some reason even though I can see the file if I log in remotely.
$fileExists = file_exists($fetch_string);
if (!$fileExists) {
die('File does not exist');
}
$stream = fopen($fetch_string, 'r');
if (!$stream) {
die("Could not open remote file: " . $fetch_string . "\n");
}
同样,同样的代码在旧服务器上有效,但在新服务器上无效。我错过了什么?我可以轻松地将文件复制到我的服务器上ssh2_scp_recv()
工作正常,所以我不确定该fopen()
功能发生了什么。