summaryrefslogtreecommitdiff
path: root/inc/remote.php
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@tinyboard.org>2011-06-04 18:55:05 +1000
committerSavetheinternet <savetheinternet@tinyboard.org>2011-06-04 18:55:05 +1000
commit36ee32b38b9cbfb04f26267cd34017c258e1a39b (patch)
treefeae2ddef128cc2caa6e50b0acc14298dfbc920b /inc/remote.php
parent2511dc447c1839c6da25afdd820d05cc03bf8472 (diff)
remote servers -- writing to another server via SSH
Diffstat (limited to 'inc/remote.php')
-rw-r--r--inc/remote.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/inc/remote.php b/inc/remote.php
new file mode 100644
index 00000000..a4c9e68a
--- /dev/null
+++ b/inc/remote.php
@@ -0,0 +1,47 @@
+<?php
+ class Remote {
+ public function __construct($config) {
+ foreach($config as $name => $value) {
+ $this->{$name} = $value;
+ }
+
+ $methods = Array();
+
+ if(!isset($this->auth['method']))
+ error('Unspecified authentication method.');
+
+ // Connect
+ $this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods);
+
+ switch($this->auth['method']) {
+ case 'plain':
+ if(!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password']))
+ error('Plain-text authentication failed.');
+ break;
+ default:
+ error('Unknown authentication method.');
+ }
+
+ }
+
+ public function write($data, $remote_path) {
+ global $config;
+
+ switch($this->type) {
+ case 'sftp':
+ $sftp = ssh2_sftp($this->connection);
+ file_write('ssh2.sftp://' . $sftp . $remote_path, $data, true);
+ break;
+ case 'scp':
+ $file = tempnam($config['tmp'], 'tinyboard-scp');
+ // Write to temp file
+ file_write($file, $data);
+
+ ssh2_scp_send($this->connection, $file, $remote_path, 0755);
+ break;
+ default:
+ error('Unknown send method.');
+ }
+ }
+ };
+?> \ No newline at end of file