एक SSH सुरंग के माध्यम से Gzipped टीएआर का उपयोग करते हुए तेज़ है। शुद्ध scp
से अधिक तेज़ी से मैग्नीट्यूड्स, विशेष रूप से कई छोटी फ़ाइलों के संबंध में। यहाँ linux कमांड लाइन के लिए एक उदाहरण है:
उपयोगकर्ता @ स्थानीय # सीडी/स्रोत /; टैर सीजीएफ - * | ssh उपयोगकर्ता @ दूरस्थ "सीडी/लक्ष्य /; टार xzf -"
अद्यतन: अनुरोध अनुसार, यहाँ आप एक शुद्ध पीएचपी समाधान के साथ जाना - यह मुश्किल सा बाहर नगण्य कुछ मज़ा था।
ध्यान दें: आप इस के लिए काम करने के लिए PHPs libssh extension की जरूरत है। इसके अलावा, एसएसडीआईएन केवल एसएसएच के लिए स्ट्रीम रैपर का उपयोग करते समय उपलब्ध है।
यह है लगभग कोई भूमि के ऊपर है, क्योंकि यह धाराओं पर सीधे काम कर रहा है और अपने CPU सबसे अधिक संभावना हमेशा नेटवर्क लिंक आप हस्तांतरण के लिए उपयोग कर रहे हैं की तुलना में तेजी है।
नेटवर्क बनाम सीपीयू गति के व्यापार के लिए, आप कमांड लाइन से -z
विकल्प को हटा सकते हैं। (कम CPU उपयोग, लेकिन तार पर और अधिक डेटा)
कोड उदाहरण:
<?php
$local_cmd = "cd /tmp/source && tar -czf - *";
$remote_cmd = "tar -C /tmp/target -xzf -";
$ssh = new SSH_Connection('localhost');
$auth = $ssh->auth_password('gast', 'gast');
$bytes = $ssh->command_pipe($local_cmd, $remote_cmd);
echo "finished: $bytes bytes of data transfered\n";
class SSH_Connection {
private $link;
private $auth;
function __construct ($host, $port=22) {
$this->link = @ssh2_connect('localhost', 22);
}
function auth_password ($username, $password) {
if (!is_resource($this->link))
return false;
$this->auth = @ssh2_auth_password($this->link, $username, $password);
return $this->auth;
}
function command_pipe ($localcmd, $remotecmd) {
if (!is_resource($this->link) || !$this->auth)
return false;
// open remote command stream (STDIN)
$remote_stream = fopen("ssh2.exec://{$this->link}/$remotecmd", 'rw');
if (!is_resource($remote_stream))
return false;
// open local command stream (STDOUT)
$local_stream = popen($localcmd, 'r');
if (!is_resource($local_stream))
return false;
// connect both, pipe data from local to remote
$bytes = 0;
while (!feof($local_stream))
$bytes += fwrite($remote_stream,fread($local_stream,8192));
// close streams
fclose($local_stream);
fclose($remote_stream);
return $bytes;
}
function is_connected() { return is_resource($this->link); }
function is_authenticated() { return $this->auth; }
}
उन्हें संग्रह और फिर कॉपी .. – Vytautas
उन्होंने स्पष्ट रूप से 'का उपयोग PHP' कहा। – Manuel
यह एक संभावित लेकिन अधिक जटिल समाधान है। –