note 82927 added to function.ssh2-scp-send
| From: | stefanov at uk dot ibm dot com | Date: | Fri, 02 May 2008 09:07:17 +0000 |
| Subject: | note 82927 added to function.ssh2-scp-send | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138989@lists.php.net to get a copy of this message | ||
In addition to my previous post, I figured out that sftp->fopen->file_get_contents->fwrite
has much better performance than ssh2_scp_send.
I've used the following code to test:
<?php
$srcFile = '/var/tmp/dir1/file_to_send.txt';
$dstFile = '/var/tmp/dir2/file_received.txt';
// Create connection the the remote host
$conn = ssh2_connect('my.server.com', 22);
// Create SFTP session
$sftp = ssh2_sftp($conn);
$sftpStream = @fopen('ssh2.sftp://'.$sftp.$dstFile, 'w');
try {
if (!$sftpStream) {
throw new Exception("Could not open remote file: $dstFile");
}
$data_to_send = @file_get_contents($srcFile);
if ($data_to_send === false) {
throw new Exception("Could not open local file: $srcFile.");
}
if (@fwrite($sftpStream, $data_to_send) === false) {
throw new Exception("Could not send data from file: $srcFile.");
}
fclose($sftpStream);
} catch (Exception $e) {
error_log('Exception: ' . $e->getMessage());
fclose($sftpStream);
}
?>
For the test I've sent three files with total size of 6kB, and the times to send including
connect to the server were:
SFTP -> 15 sec.
ssh2_scp_send -> 22 sec.
Cheers,
Pimmy
----
Server IP: 92.48.74.199
Probable Submitter: 195.212.29.92
----
Manual Page -- http://www.php.net/manual/en/function.ssh2-scp-send.php
Edit -- https://master.php.net/note/edit/82927
Del: integrated -- https://master.php.net/note/delete/82927/integrated
Del: useless -- https://master.php.net/note/delete/82927/useless
Del: bad code -- https://master.php.net/note/delete/82927/bad+code
Del: spam -- https://master.php.net/note/delete/82927/spam
Del: non-english -- https://master.php.net/note/delete/82927/non-english
Del: in docs -- https://master.php.net/note/delete/82927/in+docs
Del: other reasons-- https://master.php.net/note/delete/82927
Reject -- https://master.php.net/note/reject/82927
Search -- https://master.php.net/manage/user-notes.php