Kevin Orriss
Kevin Orriss

Reputation: 591

fopen via ssh2 sftp wrapper causes chrome ERR_EMPTY_RESPONSE

I am having problems with uploading a file over SFTP. Here is my code:

$connection = ssh2_connect("ftp.mysite.com", 22);
ssh2_auth_password($connection, "username", "password");
$sftp = ssh2_sftp($connection);
$file = "/full/path/to/file.txt";
$stream = fopen("ssh2.sftp://{$sftp}$file", "w+");

All I get is chrome saying

No data received
Error code: ERR_EMPTY_RESPONSE

I have done phpinfo() to check I have the ssh2.sftp wrapper enabled and I do. I am running PHP v4.4.0 and libssh2 v1.2.7.

Any suggestions would be appreciated!

Upvotes: 1

Views: 500

Answers (1)

manticore
manticore

Reputation: 11

You're running an old version of php. Do you have any particular reason why you can't upgrade?

I bet the issue has to do with the fact that your running such an old version. You might have better success with phpseclib, a pure PHP SFTP implementation, in light of this. You'll need PHP_Compat for it to work with php4 but assuming you have that installed (and both it and phpseclib in the include_path) it should work just fine.

sample code:

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('ftp.mysite.com');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

// puts a three-byte file named /full/path/to/file.txt on the SFTP server
$sftp->put('/full/path/to/file.txt', 'xxx');
?>

Upvotes: 1

Related Questions