SSH2 Not Working On New Server
<p>We have changed hosting companies and where ssh2 was working it no longer works. We have <code>ssh2</code> enabled on the new server along with <code>allow_url_fopen</code> enabled.</p>

<p>The only difference I can see is that the old server used <code>PHP 5.4.45</code> and the new server is using <code>PHP 5.6.28</code>.</p>

<p>However, I now get the following error.
<code>Could not open remote file: ssh2.sftp://Resource id #337/my/directory/file.txt</code></p>

<p>Here is an example of my code:</p>

<pre><code>$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");
}
</code></pre>

<p>Again, this same code works on the old server but doesn't on the new server. What am I missing? I can easily copy the file to my server with <code>ssh2_scp_recv()</code> which works fine so I'm not sure what is happening with the <code>fopen()</code> function.</p>