Shehzad Bilal
Shehzad Bilal

Reputation: 2523

fsockopen in php not working on server

Here is my code:

$fp = fsockopen("74.63.172.37", 22, $errno, $errstr, 50);

if (!$fp) {

    echo "not connected";

} else {

    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: 74.63.172.37\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    $val = "";
    if (!feof($fp)) {
        echo "<br/>".fgets($fp, 128);
    }

    if (feof($fp)) {
        echo "<br/>Not connected";
    } else {
      echo "<br/>Connected";
    }

    fclose($fp);

    die();
}

On local server it gives me an output:

trying to connect
SSH-2.0-1.82_sshlib GlobalSCAPE
Connected

Whereas on server it gives me an output:

trying to connect
Not connected

I have another sftp server, where I could connect from both server and locally. What could be the issue?

Upvotes: 0

Views: 3512

Answers (3)

Shehzad Bilal
Shehzad Bilal

Reputation: 2523

Thanks ,, I found the solution. Destination Host has blocked my Server IP address.

Upvotes: 1

Tschallacka
Tschallacka

Reputation: 28742

It is either not enabled by your ISP, or the ports are being blocked. I would suggest you contact the servicedesk.

Upvotes: 2

Robbie
Robbie

Reputation: 17720

Two options I can think of:

the destination server will only accept connections from a particular IP address, and your Web server isn't on it.

The version of Open SSL on your web server is not compatible, so the cypher used for connectivity can't be agreed. Or it's trying to fall back to protocol 1, but the destination sever is configured to only allow protocol 2 (the latest).

So - check if there is a firewall restriction on destination server, and check openssl is up to date and cyphers are all available on your web server.

Upvotes: 2

Related Questions