note 111035 deleted from function.ssh2-sftp by danbrown
| From: | danbrown@php.net | Date: | Thu, 17 Jan 2013 15:19:44 +0000 |
| Subject: | note 111035 deleted from function.ssh2-sftp by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193133@lists.php.net to get a copy of this message | ||
Note Submitter: gabriel dot rota at gmail dot com
----
Previus example don't work for me on php 4.4.5 because filesize() can't stat filesize.
I've solved this using ssh2_sftp_lstat().
<?php
$file="/path/to/file";
$session = ssh2_connect('shell.example.com', 22);
if (ssh2_auth_password($session, 'username', 'password')){
echo "Authentication Successful!<br>\n";
} else {
die('Authentication Failed...<br>');
}
$sftp = ssh2_sftp($session);
$stream = fopen("ssh2.sftp://$sftp$file",
'r') or exit("Unable to open file!");
$statinfo = ssh2_sftp_lstat($sftp, $file);
$filesize = $statinfo['size'];
echo "filesize:".$filesize."<br>\n";
$fread = fread($stream, $filesize) or exit("Unable to fread!");
echo "fread:".$fread."<br>\n";
fclose($stream);
?>