Jump to content

php-sftp - problem with fread?


herghost

Recommended Posts

Hi all

 

I am pulling my hair out trying to get the following script to work

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("*.*.*.*", 22))){
    echo "fail: unable to establish connection\n";
} else {
    // try to authenticate with username root, password secretpassword
    if(!ssh2_auth_password($con, "root", "********")) {
        echo "fail: unable to authenticate\n";
    } else {
        // allright, we're in!
        echo "okay: logged in...\n";

        // execute a command
        if (!($stream = ssh2_exec($con, "ls -al" ))) {
            echo "fail: unable to execute command\n";
        } else {
		echo "should be ok";
            // collect returning data from command
            stream_set_blocking($stream, true);
            $data = "path to file checked by logging into WINSCP and looking at properties. Is a .txt file";
		echo $data;
            while ($buf = fread($stream,4096)) {
                $data .= $buf;
            }
            fclose($stream);
        }
    }
}

 

Basically shouldnt this display the contents of the file to me?

 

On screen I just get

 

okay: logged in... should be ok

 

What is my error?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/254687-php-sftp-problem-with-fread/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.